繁体   English   中英

使用python中的Bautifulsoup从网站中提取数据

[英]extract data from website using Bautifulsoup in python

我正在尝试从网站http://www.bcsfootball.org中提取数据

在这个网站上,我希望提取包含所有文本的欢迎块。

这是我的代码

import urllib2
from bs4 import BeautifulSoup

soup = BeautifulSoup(urllib2.urlopen('http://www.bcsfootball.org').read())

for row in soup('table',{'class':mod-container mod-no-footer mod-open'})[0].tbody('tr'):
tds = row('td')
print (tds[0].string, tds[1].string)

错误

    for row in soup('table',{'class':mod-container mod-no-footer mod-open'})[0].tbody('tr'):
                                                     ^
SyntaxError: invalid syntax

请有人可以帮助我在哪里做错了? 我是python的新手

还请帮我理解[0] .tbody('tr'):代码。 它究竟做了什么?

谢谢

这段代码应该有用,你错过了一个撇号。

码:

import urllib2
from bs4 import BeautifulSoup

soup = BeautifulSoup(urllib2.urlopen('http://www.bcsfootball.org').read())

for row in soup('table',{'class':'mod-container mod-no-footer mod-open'})[0].tbody('tr'):
    tds = row('td')
print (tds[0].string, tds[1].string)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM