Hy,我正在尝试抓取一个网站https://www.dawn.com/pakistan但 python find() find_all() 方法返回空列表,我已经尝试了 html5.parser、html5lib 和 lxml 仍然没有运气。我试图抓取的类存在于源代码和汤对象中,但似乎没有工作,任何帮助将不胜感激,谢谢!
代码:
from bs4 import BeautifulSoup
import lxml
import html5lib
import urllib.request
url1 = 'https://www.dawn.com/pakistan'
req = urllib.request.Request(
url1,
data=None,
headers=
{
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
}
)
url1UrlContent=urllib.request.urlopen(req).read()
soup1=BeautifulSoup(url1UrlContent,'lxml')
url1Section1=soup1.find_all('h2', class_='story__title-size-five-text-black-
font--playfair-display')
print(url1Section1)
撒科打诨
相关分类