2014-01-15 44 views
0

当我使用BeautifulSoup 4解析http://www.madcamcnc.com/sales.html,然后查找表标记时,它会找到2.当我查看页面的html时,会看到10个表。为什么BeautifulSoup不会全部返回10?为什么BeautifulSoup找不到所有标签?

from bs4 import BeautifulSoup 

import urllib2 

page = urllib2.urlopen("http://www.madcamcnc.com/sales.html") 
soup = BeautifulSoup(page) 
print len(soup.findAll('table')) 
+0

它返回多少? – 2014-01-15 04:58:09

+0

这个问题似乎是脱离主题,因为它是关于看错网页。 – MattDMo

回答

1

查看源代码显示页面的实际HTML源代码中只有3个表格。其他表格必须在加载页面后使用Javascript添加,这是BeautifulSoup没有看到的。

BeautifulSoup只能在给定的HTML文档上工作,但不会加载或执行Javascript,因此浏览器和文档BeautifulSoup之间的差异处理。

enter image description here

+0

你怎么得到3,我得到2?我复制/粘贴源文件并搜索单词“table” - 四个匹配,每个'

'和'
'两个'... – MattDMo

+0

@MattDMo击败我...我在源代码的屏幕截图中添加了I看到。 – 2014-01-15 05:03:03

+1

aha。您正在查看'