【发布时间】:2013-06-23 01:36:42
【问题描述】:
我正在尝试使用 BeautifulSoup 解析我上传到 http://pastie.org/8070879 的 html 表,以便将三列(0 到 735、0.50 到 1.0 和 0.5 到 0.0)作为列表。为了解释原因,我希望整数 0-735 是键,十进制数是值。
通过阅读关于 SO 的许多其他帖子,我想出了以下内容,这些内容与创建我想要的列表并不接近。它所做的只是在表格中显示文本,如下所示http://i1285.photobucket.com/albums/a592/TheNexulo/output_zps20c5afb8.png
from bs4 import BeautifulSoup
soup = BeautifulSoup(open("fide.html"))
table = soup.find('table')
rows = table.findAll('tr')
for tr in rows:
cols = tr.findAll('td')
for td in cols:
text = ''.join(td.find(text=True))
print text + "|",
print
我是 Python 和 BeautifulSoup 的新手,所以请对我温柔一点!谢谢
【问题讨论】:
-
上传一张您希望数据最终呈现方式的图片。国际象棋相关问题 +1。
-
它将文本显示在表格中,因为这就是您的代码所做的。为什么不将每个字段推入字典,其中键是整数,小数列表是值?
标签: python html beautifulsoup