Python beautifulsoup未返回预期结果?
我正在读一个巨大的文件。进行简单搜索会返回明显不正确的结果 代码如下:Python beautifulsoup未返回预期结果?,python,beautifulsoup,Python,Beautifulsoup,我正在读一个巨大的文件。进行简单搜索会返回明显不正确的结果 代码如下: import urllib2 import re from bs4 import BeautifulSoup data = urllib2.urlopen('http://www.nhl.com/scores/htmlreports/20132014/PL020749.HTM') html = data.read() soup = BeautifulSoup(html, 'lxml') a = soup.findAll
import urllib2
import re
from bs4 import BeautifulSoup
data = urllib2.urlopen('http://www.nhl.com/scores/htmlreports/20132014/PL020749.HTM')
html = data.read()
soup = BeautifulSoup(html, 'lxml')
a = soup.findAll('td')
print len(a)
这就产生了
2737
但是,只要手动搜索
,我也有同样的问题。以这种方式尝试其他解析器:
soup = BeautifulSoup(html, 'html5lib')
这将解决您的问题。我按原样运行了您的代码,得到了您提到的td
元素的确切数目,15562。我怀疑您需要将您的lxml
版本或Beauty soup版本更新为最新版本。。我有lxml3.2.4和bs3.2。1@qwwqwwq我刚刚运行了sudo apt get--purge remove python-bs4
和pip uninstall beautifulsoup
和pip install lmxl--upgrade
但仍然得到2737。我对此感到非常恼火。还有其他地方可以安装有故障的beautifulsoup吗?请注意,我使用python的默认html解析器运行了此程序,并且得到了2737,因此我假设beautifulsoup存在问题,那么您使用的python版本是什么?@qwwqwq2.7。我已经删除了BS4的每一种方式,我知道如何仍然可以导入它