Xpath 和通配符

发布于 2024-10-31 06:04:09 字数 325 浏览 0 评论 0原文

我尝试了几种组合但没有成功。该数据的完整 xpath 为 .//*[@id='detail_row_seek_37878']/td 问题是每个节点的数字部分“37878”发生变化,因此我无法使用 foreach循环遍历节点。有没有办法使用通配符并将 xpath 减少为 .//*[@id='detail wildcard,以绕过绝对值部分?我在此使用 html 敏捷包。

 HtmlNode ddate = node.SelectSingleNode(".//*[@id='detail_row_seek_37878']/td");

I have tried several combinations without success. The full xpath to that data is .//*[@id='detail_row_seek_37878']/td The problem is the number portion '37878' changes for each node and thus I can't use a foreach to loop through the nodes. Is there some way to use a wildcard and reduce the xpath to .//*[@id='detail wildcard, in an effort to bypass the absolute value portion? I am using html agility pack on this.

 HtmlNode ddate = node.SelectSingleNode(".//*[@id='detail_row_seek_37878']/td");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错爱 2024-11-07 06:04:10

提取不变的部分:

//*[starts-with(@id, 'detail_row_seek')]/td

相关技术和功能

匹配 id 属性在第 7 个位置包含字符串 _row_ 的元素字符

//*[substring(@id, 7, 5)='_row_']/td 

匹配id属性在任意位置包含文本detail_的元素:

//*[contains(@id, 'detail_')]/td 

匹配id<的元素/code> 属性文本detail_row_seek结尾:

//*['detail_row_seek' = substring(@id, 
        string-length(@id) - string-length('detail_row_seek') + 1)]/td 

Extract the portion that doesn't change:

//*[starts-with(@id, 'detail_row_seek')]/td

Related Techniques and Functions

To match elements whose id attribute contains the string _row_ at the 7th character:

//*[substring(@id, 7, 5)='_row_']/td 

To match elements whose id attribute contains the text detail_ at any position:

//*[contains(@id, 'detail_')]/td 

To match elements whose id attribute ends with the text detail_row_seek:

//*['detail_row_seek' = substring(@id, 
        string-length(@id) - string-length('detail_row_seek') + 1)]/td 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文