Xpath 获取介于 2 个元素之间的元素 [英] Xpath Get elements that are between 2 elements

查看:29
本文介绍了Xpath 获取介于 2 个元素之间的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我是否可以从这个 html 片段中只选择 div 2a 和 2b?问题是 div 不是 h4 元素的子元素,因此 xpath 查询应该说获取 h4='Two' 和 h4='Two' 之后的 h4 之间的 div请注意,我希望查询是动态的,你告诉她开始元素 (h4='Two') 和结束元素(任何 h4),然后告诉她在哪个过滤器上获取元素.

can anyone tell me if its possible to select only the divs 2a and 2b from this html fragment? the problem is that the divs are not children of h4 element and so the xpath query should say like "get the divs that are between the h4='Two' and the h4 that is right after h4='Two' note that i want the query to be dynamic and u tell her the start element (h4='Two') and the end element (any h4) and then on which filter to get the elements between.

<h4>One</h4>
<div>1a</div>
<div>1b</div>
<div>1c</div>
<h4>Two</h4>
<div>2a</div>
<div>2b</div>
<h4>Three</h4>
<div>3a</div>
<div>3b</div>
<div>3c</div>

推荐答案

div[preceding-sibling::h4[1] = 'Two']

这篇关于Xpath 获取介于 2 个元素之间的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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