简体   繁体   English

Xpath和通配符

[英]Xpath and wildcards

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. 该数据的完整xpath是.//*[@id='detail_row_seek_37878']/td ' .//*[@id='detail_row_seek_37878']/td 。问题是每个节点的数字部分'37878'发生了变化,因此我无法使用foreach循环遍历节点。 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? 是否有一些方法可以使用通配符并将xpath减少到.//*[@id='detail wildcard [ .//*[@id='detail wildcard ,以便绕过绝对值部分? I am using html agility pack on this. 我正在使用html敏捷包。

 HtmlNode ddate = node.SelectSingleNode(".//*[@id='detail_row_seek_37878']/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 : 要匹配其id属性包含第7个字符的字符串_row_元素:

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

To match elements whose id attribute contains the text detail_ at any position: 要在任何位置匹配id属性包含文本detail_元素:

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

To match elements whose id attribute ends with the text detail_row_seek : 要匹配id属性文本detail_row_seek 结尾detail_row_seek

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM