簡體   English   中英

beautifulsoup返回數據為無包括 <br> 標簽

[英]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>&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屬性讀取它們的值時,我得到None作為值。 我想這是因為他們有<br>標簽。 我想要最后四個<td>數據,包括地址,電話號碼,email_id和傳真。 而不是.string我應該用什么來獲取所有這些數據?

您可以使用.text來獲取文本。

編輯:

另一種選擇可能是使用.contents獲取每個元素並根據需要加入它們。

獲得td元素的句柄后,您可以使用:

 td.findAll(text=True) 

獲取td標記的文本子元素列表。 然后你可以join該列表,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM