如何使用汤&python从Wikipedia的表中的特定列下的内容

我需要从维基百科的表格中获取内容指向特定列下的href链接。 该页面是“ http://en.wikipedia.org/wiki/List_of_Telugu_films_of_2015 ”。 在这个页面上,有几个表格“wikitable”。 我需要列标题下的内容的链接,他们指向的每一行。 我希望将它们复制到Excel表格中。

我不知道在一个特定的列下search的确切代码,但我到这里来,我得到一个“Nonetype对象不可调用” 。 我正在使用bs4。 我想提取至less部分表格,所以我可以弄清楚我想要的标题列下的href链接,但是我以这个错误结束。 代码如下:

from urllib.request import urlopen from bs4 import BeautifulSoup soup = BeautifulSoup(urlopen('http://en.wikipedia.org/wiki/List_of_Telugu_films_of_2015').read()) for row in soup('table', {'class': 'wikitable'})[1].tbody('tr'): tds = row('td') print (tds[0].string, tds[0].string) 

一点指导赞赏。 有谁知道?

发现无types错误可能与表过滤有关。 更正的代码如下:

 import urllib2 from bs4 import BeautifulSoup, SoupStrainer content = urllib2.urlopen("http://en.wikipedia.org/wiki/List_of_Telugu_films_of_2015").read() filter_tag = SoupStrainer("table", {"class":"wikitable"}) soup = BeautifulSoup(content, parse_only=filter_tag) links=[] for sp in soup.find_all(align="center"): a_tag = sp('a') if a_tag: links.append(a_tag[0].get('href'))