Skip to main content
 首页 » 编程设计

python美汤提取数据

2025年05月04日8yjmyzz

我正在使用 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 每日交易量,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") ] 

我得到一个需要组织的数据列表

有什么简单的建议吗??

谢谢

请您参考如下方法:

list(soup.stripped_strings) 

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