我一直在使用 Python Beautifulsoup 来抓取数据。至此已经成功刮取。但坚持使用以下网站。
目标站点:LyricsHindiSong
我的目标是从提到的网站上抓取歌词。但它总是给出空白结果或 Nonetype 对象没有属性类型错误。
自过去 15 天以来一直在苦苦挣扎,无法弄清楚问题出在哪里以及如何解决?
以下是我正在使用的代码。
import pymysql
import requests
from bs4 import Beautifulsoup
r=requests.get("https://www.lyricshindisong.in/2020/04/chnda-re-chnda-re-chhupe-rahana.html")
soup=Beautifulsoup(r.content,'html5lib')
pageTitle=soup.find('h1').text.strip()
targetContent=soup.find('div',{'style':'margin:25px; color:navy;font-size:18px;'})
print(pageTitle)
print(targetContent.text.strip())
Run Code Online (Sandbox Code Playgroud)
它打印错误 nonetype 对象没有文本错误。如果我检查检查窗口,元素同时存在两个元素。无法理解问题出在哪里。至少它应该打印标题页。
希望你明白我的要求。请指导我。谢谢。