我正在尝试从具有多行(如下所示)的网页中提取href链接,但我只想要那些具有<b>
块
<tr bgcolor="#ffffff">
<td>
<a href="?6384593.html" style="background-color: transparent;">
<span class="ts">
<font size="1">
<font color="#006633">
</font>
</font>
<b>Lee Swanson Research Update</b>
<font color="#7777CC"> - Swanson Health Products</font></span>
</a>
</td>
</tr>
在这种情况下,我使用xpath表达式“// b”来查找粗体标记,但我特别想要的是一个href链接。这有可能用xpath吗?
答案 0 :(得分:2)
//b/ancestor::a[1]/@href
尝试类似上面的内容
答案 1 :(得分:2)
以下 XPATH 将起作用:
//a[.//*[local-name(.)='b']]/@href
更新 AS @Jens Erat建议。
//a[.//b]/@href