通过寻找另一个标签获得href

时间:2013-10-03 20:08:34

标签: xpath

我正在尝试从具有多行(如下所示)的网页中提取href链接,但我只想要那些具有<b>

的href
<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吗?

2 个答案:

答案 0 :(得分:2)

//b/ancestor::a[1]/@href

尝试类似上面的内容

答案 1 :(得分:2)

以下 XPATH 将起作用:

//a[.//*[local-name(.)='b']]/@href

更新 AS @Jens Erat建议。

//a[.//b]/@href