xml - XPath follow-sibling 从 <td> 获取文本

标签 xml selenium xpath

通过 XPath ,我正在尝试获取位于第二个 <td> 中的文本值(文本: 0.56 )通过专门使用 following-sibling和关键字 ( . = 'Vitamin D' )。

<html>
    <body>
        <td><a href="http://website.com/12345.php">Vitamin D</a></td>
        <td>0.56</td>
        <td>µg</td>
        <td>5</td>
    </body>
</html>

到目前为止,我已经成功识别出第一个 <td> 中的文本。通过其链接内容:

//a[starts-with(@href, 'http://website.com/') and . = 'Vitamin D']

<小时/>

我已经尝试过这个和其他替代方案,但我没有得到正确的结果:

//a[starts-with(@href, 'http://website.com/') and . = 'Vitamin D']/following-sibling::td

//a[starts-with(@href, 'http://website.com/') and . = 'Vitamin D']following-sibling::text()

最佳答案

td 上使用以下同级,即 //td[a[starts-with(@href, 'http://website.com/') 和 . =“维生素 D”]]/following-sibling::td[1]

关于xml - XPath follow-sibling 从 <td> 获取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35875817/

相关文章:

xml - 有条件地在 XML 文字中包含属性

xml - 在 R 中抓取网页时出现问题

python-3.x - Python Selenium 错误 - 在 (207.1666717529297,25) 处不可点击,因为另一个元素 <div id ="overley"class ="over_ley"> 遮挡了它

xml - XSLT 将结果分成 3 组

c# - 数组中的一个或两个 JSON 反序列化

c# - 如何从 xelement 中提取 cdata 的值?

python - Selenium 对我来说真的很慢,我的代码有问题吗?

javascript - 选择窗口无法选择子窗口

python - 创建循环以在 scrapy/python 中解析表数据

css - Selenium CSS 选择器 :visible is not a valid selector