我正在尝试使用 BeautifulSoup提取此数据表的第一列和第三列。从 HTML 来看,第一列有一个<th>
标签。感兴趣的另一列具有<td>
标记。无论如何,我所能得到的只是带有标签的列的列表。但是,我只想要文字。
table
已经是一个列表,所以我不能使用findAll(text=True)
. 我不确定如何以另一种形式获取第一列的列表。
from BeautifulSoup import BeautifulSoup
from sys import argv
import re
filename = argv[1] #get HTML file as a string
html_doc = ''.join(open(filename,'r').readlines())
soup = BeautifulSoup(html_doc)
table = soup.findAll('table')[0].tbody.th.findAll('th') #The relevant table is the first one
print table