使用BeautifulSoup4从网站提取表格信息

时间:2016-10-26 15:44:57

标签: python python-3.x beautifulsoup

我非常喜欢BeautifulSoup noob,我试图从网站flashscores.co.uk中提取匹配分数,但运气不佳!

到目前为止,这是我的代码:

import urllib2
from bs4 import BeautifulSoup

flash = "http://www.flashscore.com/soccer/england/premier-league/results/"

prem = urllib2.urlopen(flash)

soup = BeautifulSoup(prem, "html.parser")

table = soup.find('table', {'class': 'soccer'})

for row in table.FindAll("span")

print (row.text)

这是我尝试从中提取信息的页面源的图像。一个很好的起点是显示: 切尔西4 曼彻斯特联队0

Page Source

非常感谢任何帮助/建议!

1 个答案:

答案 0 :(得分:0)

包含表信息的HTML实际上是由JavaScript生成的。 urllib2不会处理JavaScript。

您在浏览器处理JavaScript 后,作为“页面源”链接的内容实际上是DOM 。如果您在禁用javascript的情况下加载页面,您会发现结果永远不会加载。

相反,您需要使用selenium之类的东西来处理JavaScript。