1 回答
TA贡献1864条经验 获得超6个赞
我改进/更正了代码,现在它将打印每行的条目文本列表列表。
代码需要一次安装 beautiful soup 和 lxml:python -m pip install lxml bs4
。
# 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')])
代码打印:
[['{99}Receivables becoming Defaulted Receivables during period', '1,310,326.05']]
添加回答
举报