【发布时间】:2020-03-08 19:29:39
【问题描述】:
所以基本上我想提取里面的文字
<div class = "examplediv">
example text
</div>
我用过
url='https://sample.com'
headers={"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'}
page = requests.get(url, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
data = soup.find("div", {"class":"examplediv"})
clean_data = data.text
print(clean_data)
但它永远不会在终端返回“无”。
我该怎么办?
【问题讨论】:
标签: python html web-scraping beautifulsoup