首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从edgar抓取特定数据

从edgar抓取特定数据
EN

Stack Overflow用户
提问于 2020-09-26 07:57:50
回答 1查看 47关注 0票数 1

有一段HTML代码

代码语言:javascript
复制
<tr bgcolor="#cceeff" style="page-break-inside:avoid ; font-family:Def.-Times; font-size:8pt">
<td colspan="3" valign="top"> <p style=" margin-top:0pt ; margin-bottom:0pt; margin-left:2.00em; text-indent:-1.00em; font-size:8pt; font-family:ARIAL"><b>{99}</b> <b></b>Receivables becoming Defaulted Receivables during period</p></td>
<td align="right" valign="bottom"><font style="font-family:ARIAL; ">1,310,326.05</font></td>
 <td nowrap="nowrap" valign="bottom"><font style="font-family:ARIAL; "> </font></td>
 <td valign="bottom"> </td>
 <td valign="bottom"></td>
 <td valign="bottom"></td>

我如何提取这样的数据

代码语言:javascript
复制
{4}Defaulted Receivables', '{4}', '1,310,326.05']

我有一个人给我的密码

代码语言:javascript
复制
def get_row(soup, n):
    return [td.get_text(strip=True) for td in soup.select('tr:contains("{' + str(n) + '}") td') if td.get_text(strip=True)]

但首先,我不明白如何在HTML代码中找到“行”。第二,tr:contains("{' + str(n) + '}") td这个代码是干什么的??抱歉,我对刮擦和HTML太陌生了

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-26 09:06:57

我已经改进/更正了代码,现在它将打印每一行的条目列表。

代码需要漂亮的汤和lxml才能安装一次:python -m pip install lxml bs4

在网上试试!

代码语言:javascript
复制
# Needs: python -m pip install lxml bs4
import lxml
from bs4 import BeautifulSoup

soup = BeautifulSoup("""
<tr bgcolor="#cceeff" style="page-break-inside:avoid ; font-family:Def.-Times; font-size:8pt">
<td colspan="3" valign="top"> <p style=" margin-top:0pt ; margin-bottom:0pt; margin-left:2.00em; text-indent:-1.00em; font-size:8pt; font-family:ARIAL"><b>{99}</b> <b></b>Receivables becoming Defaulted Receivables during period</p></td>
<td align="right" valign="bottom"><font style="font-family:ARIAL; ">1,310,326.05</font></td>
 <td nowrap="nowrap" valign="bottom"><font style="font-family:ARIAL; "> </font></td>
 <td valign="bottom"> </td>
 <td valign="bottom"></td>
 <td valign="bottom"></td>
</tr>
""", 'lxml')

print([[
    td.get_text(strip=True) for td in tr.select('td') if td.get_text(strip=True)
] for tr in soup.select('tr')])

代码打印:

代码语言:javascript
复制
[['{99}Receivables becoming Defaulted Receivables during period', '1,310,326.05']]
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64075251

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档