gpt4 book ai didi

python - beautifulsoup 以 None 形式返回包含
标签的数据

转载 作者:太空狗 更新时间:2023-10-30 01:16:57 26 4
gpt4 key购买 nike

我有这样一个表格数据:

<table class="tablesorter" id="dea">
<thead>
<tr>
<th class="header ">Name</th>
<th class="header">City</th>
<th class="">Address</th>
<th class="">Phone Nos</th>
<th class="">Email</th>
<th class="">Fax</th>
</tr>
</thead>
<tbody>

<tr class="info">
<td style="font:bold 12px Tahoma; color:#1f2c48;">Audi California</td>
<td>&nbsp;California&nbsp;</td>
<td align="left">
A?85, bay Area, Phase 1, <br>
California<br>
California
- 6554655
</td>
<td align="right">
<br>4747744747<br>108388383
</td>
<td align="center">
info<!-- >@_ -->@<!-- >@_ -->audiCal<!-- >@_ -->.<!-- >@_ -->net
</td>
<td align="right">
&nbsp;
</td>
</tr></tbody>
</table>

我正在使用 beautifulsoup 来解析它,但现在我在从最后四个中获取数据时遇到了问题 <td> .每当我使用 .string 读取它们的值时属性(property),我得到None作为值(value)。我想这是因为他们有 <br>标签。我要最后四个<td>具有地址、电话号码、email_id 和传真的数据。而不是 .string我应该使用什么来获取所有这些数据?

最佳答案

您可以使用 .text 获取文本。

编辑:

另一种选择可能是使用 .contents 获取每个元素并在必要时加入它们。

关于python - beautifulsoup 以 None 形式返回包含 <br> 标签的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9091811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com