select an element next to current element HtmlAgilityPack

大兔子大兔子 提交于 2019-12-23 01:52:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!