选择当前元素HtmlAgilityPack旁边的元素 [英] select an element next to current element HtmlAgilityPack

查看:48
本文介绍了选择当前元素HtmlAgilityPack旁边的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用HtmlAgilityPack解析html页面.我想选择一个标签h3的集合,然后遍历它,对于每个h3元素,我都希望在它旁边选择一个元素.这是我的示例HTML:

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>

我知道如何选择h3的集合,但是我不知道如何在每个旁边选择ul

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

推荐答案

如果当前节点为h3,请使用以下XPath:

If current node is h3, use this XPath:

following-sibling::ul[1]

它选择1 st ul个兄弟姐妹.

It selects 1st ul sibling.

这篇关于选择当前元素HtmlAgilityPack旁边的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆