使用 xpath 定位具有特定值的 td [英] Locate a td with a specific value using xpath

查看:40
本文介绍了使用 xpath 定位具有特定值的 td的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下 html 片段:

Consider the following html fragment:

<table>
  <tr>
    <td>One</td><td>1</td>
    <td>Two</td><td>2</td>
  </tr>
</table>

我想使用 xpath 根据第一个 td(一个"或两个")的值来查找第二个 td(1"或2").例如:

I want to use xpath to find the second td ("1" or "2") based on the value of the first td ("One" or "Two). Something like:

/table/tr/td[text() = 'One']/../td

/table/tr/td[text(), 'One']/../td

有什么想法吗?

推荐答案

/table/tr/td[text()='One']/following-sibling::td[1]

带有文本Onetd节点的第一个td后续兄弟"

"The first td following-sibling of a td node with text One"

这篇关于使用 xpath 定位具有特定值的 td的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆