Agility Pack for HTML Find ids that begin with

.net c# html-agility-pack xml xpath

Question

I am using XPath for the first time and am trying to collect data from a website. I need to locate the following two things:

1- all span tags with the following initialsctl00_Main_GridView_lieutenants

2- the span's parent tag's href is erroneous. Let me attempt to explain:

<a href="something.html"><span id="ctl00_Main_GridView_lieutenants_ctl03_lbl_nick">Text</span></a>

I need both the text and the link.

1
7
8/30/2011 12:34:41 PM

Accepted Answer

//span[starts-with(@id, 'ctl00_Main_GridView_lieutenants')]

chooses every span which@id begins withctl00_Main_GridView_lieutenants

//a[span[starts-with(@id, 'ctl00_Main_GridView_lieutenants')]]/@href

picks all@href of a which are parentsspan which @id begins withctl00_Main_GridView_lieutenants

11
8/30/2011 12:32:01 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow