【发布时间】:2017-07-22 02:40:05
【问题描述】:
我需要在下面的代码 sn-p 中提取结束标记和
标记之间存在的数据:
<td><b>First Type :</b>W<br><b>Second Type :</b>65<br><b>Third Type :</b>3</td>
我需要的是:W, 65, 3
但问题是这些值也可以是空的,比如-
<td><b>First Type :</b><br><b>Second Type :</b><br><b>Third Type :</b></td>
如果存在这些值,我想获取这些值,否则为空字符串
我尝试使用 nextSibling 和 find_next('br') 但它返回了
<br><b>Second Type :</b><br><b>Third Type :</b></br></br>
和
<br><b>Third Type :</b></br>
如果标签之间不存在值(W、65、3)
</b> and <br>
我需要的是,如果这些标签之间没有任何内容,它应该返回一个空字符串。
【问题讨论】:
-
嘿,
next_sibling最终对我来说很好:)
标签: python beautifulsoup html-parsing