问题
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
回答1:
If current node is h3
, use this XPath:
following-sibling::ul[1]
It selects 1stul
sibling.
来源:https://stackoverflow.com/questions/13813877/select-an-element-next-to-current-element-htmlagilitypack