gpt4 book ai didi

xml - 一个节点中的一个节点的 xpath,该节点是另一个节点的兄弟节点

转载 作者:行者123 更新时间:2023-12-03 16:12:41 25 4
gpt4 key购买 nike

假设我有一些看起来像这样的 html:

<section>
<header>
<h1>Foo</h1>
</header>
<section>
<a href="#">one</a>
</section>
<section>
<a href="#">two</a>
</section>
</section>
<section>
<header>
<h1>Bar</h1>
</header>
<section>
<a href="#">one</a>
</section>
<section>
<a href="#">two</a>
</section>
</section>

我想获取带有“two”文本的 anchor ,但必须属于具有“Bar”标题的部分标签(即上述 html 中的最后一个 anchor )。

获取带有 Bar 文本的标题元素很容易:
//header/h1[text()='Bar']

使用位于 section 元素中的文本“two”来获取两个 anchor 也很容易:
//section/a[text()='two']

这当然会返回两个 anchor 。

我只是不确定如何将两者结合起来,这样我只会在节元素中找到 anchor ,该元素是包含“Bar”的标题元素的兄弟元素。

最佳答案

//section[header/h1 = 'Bar']/section/a[. = 'two']

关于xml - 一个节点中的一个节点的 xpath,该节点是另一个节点的兄弟节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7266657/

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