调用函数find()beautifulsoup时结果不完整

时间:2017-02-15 15:22:02

标签: python html python-3.x beautifulsoup web-crawler

我试图抓住这个elsewhere用于研究目的,但我的结果不完整:

node-webworker-threads

它给了我这个结果:

opener = urllib.request.build_opener()
opener.addheaders = [('User-Agent', 'Mozilla/5.0')]
response = opener.open(url)
soup = BeautifulSoup(response, 'html.parser')
article = soup.find("div", { "class" : "entry" })
print(article)

但是当我查看页面的代码来源时,我可以看到更多内容:

<div class="entry">
<header><strong>Racial Forensics in an Age of Race Denial</strong></header></div>

此网址与我处理过的很多其他网址之间的区别在于标记<div class="entry"> <header><strong>Racial Forensics in an Age of Race Denial</strong></p> </header> <p>Austen Layard<br/> <a href="http://www.theoccidentalobserver.net/2014/01/racial-forensics-in-an-age-of-race-denial/"><strong>Occidental Observer</strong></a><br/> February 3, 2014</p> .... </div> 的存在。

该标签是我问题的根源吗? 如何检索标记header的全部内容?

1 个答案:

答案 0 :(得分:1)

soup = BeautifulSoup(response, 'lxml')

html.parser不稳定且非常不推荐,默认情况下,bs4使用lxml,让我们保持默认状态。