BeatutifulSoup的findAll功能无法获得所有需要的部件

时间:2013-09-10 03:50:28

标签: python beautifulsoup

我目前正在使用BeautifulSoup findAll函数来提取网页的所需属性。但是它无法获得所有需要的部件并返回None部分部件。我的python代码就像这样:

from bs4 import BeautifulSoup
import urllib

url = 'http://code.google.com/p/android/issues/detail?id=1060&colspec=ID Type Status Owner Summary Stars Opened Closed Modified Reporter Cc Project Reportedby Priority Version Target Milestone Component MergedInto BlockedOn Blocking Blocked Subcomponent Attachments'
issue_page = urllib.urlopen(url).read()

soup = BeautifulSoup(issue_page)
comment_parts =  soup.findAll(name = 'div',attrs={'class':'cursor_off vt issuecomment'})
for comment_part in comment_parts:
    print str(comment_part)+'\n'

它只获得前48个,第49个和后续的不返回。我查看了源代码相应的html页面,第49页与第48页和之前的页面相同。我真的无法弄清楚为什么会发生这种情况!有人可以帮帮我吗?非常感谢!

1 个答案:

答案 0 :(得分:1)

当我执行你的代码时,我得到58个结果。

... Your code ...
print len(comment_parts)

......和,

print comment_parts[-1]

打印页面上的最后一项。你有不同的东西吗?