[英]beautifulsoup returning data as None that includes <br> tag
我有這樣的表數據:
<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> California </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">
</td>
</tr></tbody>
</table>
我正在使用beautifulsoup來解析這個,但是現在我從最后四個<td>
獲取數據時遇到了問題。 每當我使用.string
屬性讀取它們的值時,我得到None
作為值。 我想這是因為他們有<br>
標簽。 我想要最后四個<td>
數據,包括地址,電話號碼,email_id和傳真。 而不是.string
我應該用什么來獲取所有這些數據?
您可以使用.text
來獲取文本。
編輯:
另一種選擇可能是使用.contents
獲取每個元素並根據需要加入它們。
獲得td
元素的句柄后,您可以使用:
td.findAll(text=True)
獲取td
標記的文本子元素列表。 然后你可以join
該列表,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.