Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 就像BeautifulSoup的例子一样……什么';怎么了?_Python - Fatal编程技术网

Python 就像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

因此,我尝试使用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('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
),其中(大概)只有一个表