本文介绍了Xpath和通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了几种组合,但均未成功.该数据的完整xpath是.//*[@id='detail_row_seek_37878']/td问题是每个节点的数字部分'37878'发生了变化,因此我无法使用foreach遍历这些节点.是否有某种方法可以使用通配符并将xpath减小为.//*[@id='detail wildcard,从而绕过绝对值部分?我正在为此使用html敏捷包.

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");

推荐答案

提取不变的部分:

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

相关技术和功能

要匹配其id属性在第7个字符处包含字符串_row_ 的元素:

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

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

要匹配其id属性包含文本detail_的元素,在任何位置:

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

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

要匹配其id属性结尾为文本detail_row_seek的元素:

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

这篇关于Xpath和通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 01:32