select an element next to current element HtmlAgilityPack

c# html-agility-pack

Question

I'm using HtmlAgilityPack to parsing html page. I want to select a collection of tag h3 then loop through it, and for each h3 element, i want to select a element right next to it. Here is my sample Html:

<h3>Somthing here</h3>
<ul>list of something</ul>

<h3>Somthing here</h3>
<ul>list of something</ul>

<h3>Somthing here</h3>
<ul>list of something</ul>

<h3>Somthing here</h3>
<ul>list of something</ul>

<h3>Somthing here</h3>
<ul>list of something</ul>

I know how to select collection of h3, but i don't have any ideas how to select ul next to each

Popular Answer

If current node is h3, use this XPath:

following-sibling::ul[1]

It selects 1st ul sibling.



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