我一直在使用 BeautifulSoup 进行网页抓取,这是我第一次遇到这样的问题。我试图在代码中选择数字 101,172,但即使我使用 .find 或 .select,输出始终只是标签,而不是数字。我以前做过类似的数据收集工作,没有遇到任何问题
<div class="legend-block legend-block--pageviews">
<h5>Pageviews</h5><hr>
<div class="legend-block--body">
<div class="linear-legend--counts">
Pageviews:
<span class="pull-right">
101,172
</span>
</div>
<div class="linear-legend--counts">
Daily average:
<span class="pull-right">
4,818
</span>
</div></div></div>
我用了:
res = requests.get(wiki_page, timeout =None)
soup = bs4.BeautifulSoup(res.text, 'html.parser')
ab=soup.select('span[class="pull-right"]')
#print(i)
print(ab)
输出:
[<span class="pull-right">\n<label class="logarithmic-scale">\n<input
class="logarithmic-scale-option" type="checkbox"/>\n Logarithmic scale
</label>\n</span>, <span class="pull-right">\n<label class="begin-at-
zero">\n<input class="begin-at-zero-option" type="checkbox"/>\n Begin at
zero </label>\n</span>, <span class="pull-right">\n<label class="show-
labels">\n<input class="show-labels-option" type="checkbox"/>\n Show
values </label>\n</span>]
此外,我正在寻找的数据编号是动态的,所以我不确定 Javascript 是否会影响 BeautifulSoup