【发布时间】:2015-05-01 15:55:39
【问题描述】:
我有一个 html 文档,我想从中提取表格并美化表格。到目前为止我所拥有的是:
with open('html.txt','r') as file1:
read_f=file1.read()
soup = BeautifulSoup(read_f)
the_soup=soup.findAll('table', {'id': 'table_id'})
with open('prettified.txt','w') as f2:
f2.write(the_soup.prettify())
但是我得到一个错误 prettify is no an attribute。
【问题讨论】:
-
是否有多个
'table_id'? -
或者它应该是类。然而,我正在阅读具有相同 id 的凌乱 html 表格。
标签: python python-3.x beautifulsoup