您可以尝试以下代码:
import urllib2from BeautifulSoup import BeautifulSoupurl = "http://www.samhsa.gov/data/NSDUH/2k10State/NSDUHsae2010/NSDUHsaeAppC2010.htm"soup = BeautifulSoup(urllib2.urlopen(url).read())for row in soup.findAll('table')[0].tbody.findAll('tr'): first_column = row.findAll('th')[0].contents third_column = row.findAll('td')[2].contents print first_column, third_column
如您所见,代码只是连接到url并获取html,BeautifulSoup找到第一个表,然后找到所有“ tr”并选择第一列(即“ th”)和第三列,即一个“
TD”。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)