Xpath and wildcards

一曲冷凌霜 提交于 2019-12-14 02:05:26

问题


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

回答1:


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 


来源:https://stackoverflow.com/questions/5607592/xpath-and-wildcards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!