gpt4 book ai didi

html - XPath 子集选择

转载 作者:数据小太阳 更新时间:2023-10-29 02:02:37 31 4
gpt4 key购买 nike

我有以下 XML(实际上是 HTML):

<html>
<h4>something</h4>
<p>a</p>
<p>b</p>
<h4>otherthing</h4>
<p>c</p>
</html>

XPath 能否选择跟随第一个“h4”节点的兄弟节点但不跟随第二个“h4”节点的兄弟节点的“p”节点(仅选择“p”节点 a 和 b)?

最佳答案

我的看法

//p[preceding-sibling::h4[1] and not(preceding-sibling::h4[position() > 1])]

找到所有 p 元素,它们是第一个 h4 的兄弟元素,但不是同一轴上任何其他 h4 的兄弟元素

备选

//h4[1]/following-sibling::p[count(preceding-sibling::h4) = 1]

找到第一个 h4 元素的所有后续 p 元素,这些元素恰好有一个前面的 h4 元素

关于html - XPath 子集选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3590614/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com