简体   繁体   中英

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

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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