Python 就像BeautifulSoup的例子一样……什么';怎么了?
因此,我尝试使用beautifulsoup来清理这个词汇表: 我试着刮它,就像我刮这张足球队的桌子一样: 第一种情况:Python 就像BeautifulSoup的例子一样……什么';怎么了?,python,Python,因此,我尝试使用beautifulsoup来清理这个词汇表: 我试着刮它,就像我刮这张足球队的桌子一样: 第一种情况: import urllib2 from bs4 import BeautifulSoup url = 'http://www.homeplate.kr/korean-baseball-vocabulary' page = urllib2.urlopen(url) soup = BeautifulSoup(page.read()) for row in soup('tab
import urllib2
from bs4 import BeautifulSoup
url = 'http://www.homeplate.kr/korean-baseball-vocabulary'
page = urllib2.urlopen(url)
soup = BeautifulSoup(page.read())
for row in soup('table',{'class': 'tableizer-table'}):
tds = row('td')
print tds[0].string, tds[1].string
这只输出表的一行
第二种情况:
import urllib2
from bs4 import BeautifulSoup
soup = BeautifulSoup(urllib2.urlopen('http://www.bcsfootball.org').read())
for row in soup('table',{'class': 'mod-data'})[0].tbody('tr'):
tds = row('td')
print tds[0].string, tds[1].string
这将输出所有25所学校的排名和学校名称
这两个示例之间我做错了什么?其中只有一个示例有
…[0].tbody('tr')
在第一个代码片段中,您正在迭代表(尽管变量名为row
),其中(大概)只有一个表