【问题标题】:python beautiful soup extract datapython美汤提取数据
【发布时间】:2012-08-01 12:20:00
【问题描述】:

我正在使用 Beautiful Soup 4.0 解析一个 html 文档。

这是文档中的表格示例

<tr>
<td class="nob"></td>
<td class="">Time of price</td>
<td class=" pullElement pullData-DE000BWB14W0.teFull">08/06/2012</td>
<td class=" pullElement pullData-DE000BWB14W0.PriceTimeFull">11:43:08&nbsp;</td>
<td class="nob"></td>
</tr>
<tr>
<td class="nob"></td>
<td class="">Daily volume (units)</td>
<td colspan="2" class=" pullElement pullData-DE000BWB14W0.EWXlume">0</td>
                <td class="nob"></td>
<t/r>

我想提取 08/06/2012 和 11:43:08  DAily volume,0 等。

这是我查找特定表及其所有数据的代码

html = file("some_file.html")
soup = BeautifulSoup(html)
t = soup.find(id="ctnt-2308")
dat = [ map(str, row.findAll("td")) for row in t.findAll("tr") ]

我得到一个需要整理的数据列表

有什么简单的方法吗??

谢谢

【问题讨论】:

  • 你有表格格式的 - 你从那里尝试了什么?
  • @yeback,19 个问题和两个接受的答案。我可能会继续回答这个问题
  • @Mike:谁在乎答案是否被接受?叶巴赫:你的问题是什么?您发布的代码有效。还不够“简单”吗?

标签: python beautifulsoup


【解决方案1】:
list(soup.stripped_strings)

将为您提供该汤中的所有字符串(删除所有尾随空格)

【讨论】:

    猜你喜欢
    • 2017-12-11
    • 2015-03-18
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    相关资源
    最近更新 更多