beautifulsoup没有返回预期的结果?

时间:2014-01-23 05:41:10

标签: python beautifulsoup

我正在尝试阅读GIGANTIC文件。进行简单搜索会返回明显不正确的结果!

继承人代码:

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

但是,只需在sublime文本中手动搜索<td即可显示此源代码中有15562 td个元素。

td是最简单的例子。我搜索的任何其他东西的返回方式也低于预期。 beautifulsoup只解析那么多行然后退出吗?或者我做了明显错误的事情?

由于

1 个答案:

答案 0 :(得分:0)

我和你有同样的问题。用这种方式尝试不同的解析器:

soup = BeautifulSoup(html, 'html5lib')

这将解决您的问题。

相关问题