HTML Agility Pack Find ids starting with

.net c# html-agility-pack xml xpath

Question

I am a completly noob on XPath, I am doing application to fetch data from a website, and I need to find 2 things:

1- all the span tags that start with: ctl00_Main_GridView_lieutenants

2- the href of the parent tag on the span.... errr.. I will try to explain:

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

I need the Text and the link ;)

Accepted Answer

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

Selects all span which @id starts with ctl00_Main_GridView_lieutenants

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

Selects all @href of a which have child span which @id starts with ctl00_Main_GridView_lieutenants



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why