【发布时间】:2017-01-08 02:44:36
【问题描述】:
我是 python 和 html 的新手。我正在尝试使用请求和 BeautifulSoup 从页面中检索 cmets 的数量。
在此示例中,我试图获取数字 226。这是我在 Chrome 中检查页面时看到的代码:
<a title="Go to the comments page" class="article__comments-counts" href="http://www.theglobeandmail.com/opinion/will-kevin-oleary-be-stopped/article33519766/comments/">
<span class="civil-comment-count" data-site-id="globeandmail" data-id="33519766" data-language="en">
226
</span>
Comments
</a>
当我从 URL 请求文本时,我可以找到代码,但 span 标签之间没有内容,没有 226。这是我的代码:
import requests, bs4
url = 'http://www.theglobeandmail.com/opinion/will-kevin-oleary-be-stopped/article33519766/'
r = requests.get()
soup = bs4.BeautifulSoup(r.text, 'html.parser')
span = soup.find('span', class_='civil-comment-count')
返回这个,和上面一样,但是没有226。
<span class="civil-comment-count" data-id="33519766" data-language="en" data-site-id="globeandmail">
</span>
我不知道为什么该值没有出现。提前感谢您的任何帮助。
【问题讨论】:
标签: python beautifulsoup