gpt4 book ai didi

html - Xpath表达式-在两个已知标签之间选择

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

鉴于以下HTML:

<body>
<h2>
<span class="mw-headline" id="KNOWNID">S</span>
<span class="mw-editsection">
<span class="mw-editsection-bracket">[</span>
<a href="/w/index.php?title=Og&amp;action=edit&amp;section=4">Bn</a>
<span class="mw-editsection-bracket">]</span>
</span>
</h2>
<div class="h"></div>
<p>M</p>
<p>M</p>
<p>M</p>
<p>M</p>
<p>M</p>
<h2>
<span class="mw-headline" id="NEXTKNOWNID">S</span>
<span class="mw-editsection">
<span class="mw-editsection-bracket">[</span>
<a href="/w/index.php?title=Og&amp;action=edit&amp;section=4">Bn</a>
<span class="mw-editsection-bracket">]</span>
</span>
</h2>
</body>


我有 ID="KNOWNID“,需要选择所有 <p></p>元素,直到 id="NEXTKNOWNID"。如何使用XPATH将其组合?

谢谢

最佳答案

使用preceding-siblingfollowing-sibling

//p[preceding-sibling::h2/span[@id="KNOWNID"] and following-sibling::h2/span[@id="NEXTKNOWNID"]]

关于html - Xpath表达式-在两个已知标签之间选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28360336/

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