2012-12-11 108 views
1

我使用HtmlAgilityPack来解析html页面。我想选择一个标签h3的集合,然后遍历它,并且对于每个h3元素,我想选择它旁边的一个元素。这里是我的示例HTML:选择当前元素旁边的元素HtmlAgilityPack

<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> 

我知道如何选择H3的集合,但我没有任何想法如何选择UL旁边的每个

回答

2

如果当前节点为h3,使用的XPath :

following-sibling::ul[1] 

它选择1 STul兄弟节点。

+0

你的意思是:h3Node.selectSingleNode(“following-sibling :: ul [1]”)? –