beautifulsoup find_all错误? [英] beautifulsoup find_all bug?

查看:153
本文介绍了beautifulsoup find_all错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如今,我正在使用漂亮的汤来解析html页面.但是有时我通过find_all得到的结果少于页面数.例如,此页面 http://www.totallyfreestuff. com/index.asp?m = 0& sb = 1& p = 5 具有18个标题范围.但是,当我使用以下代码时,它只有两个!谁能告诉我为什么.预先谢谢你!

Nowadays I am using beautiful soup to parse the html page. But sometimes the result I got by find_all is less than the number in pages. For example, this page http://www.totallyfreestuff.com/index.asp?m=0&sb=1&p=5 has 18 headline span. But when i use the following codes, it just got two! Can anybody tell me why. Thank you in advance!

soup = BeautifulSoup(page, 'html.parser')
hrefDivList = soup.find_all("span", class_ = "headline")
#print hrefDivList
print len(hrefDivList)

推荐答案

您可以尝试对Beautifulsoup使用其他解析器.

You can try using different parser for Beautifulsoup.

import requests
from bs4 import BeautifulSoup

url = "<your url>"
r = requests.get(url)

soup = BeautifulSoup(r.content, 'lxml')
hrefDivList = soup.find_all("span", attrs={"class": "headline"})
print len(hrefDivList)

这篇关于beautifulsoup find_all错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆