Xpath 获取两个元素之间的元素,其中我们无法使用 id 或文本来标识第二个标签

Cyb*_*lle 7 html xpath boolean-logic

我对这个问题有类似的问题Xpath Get elements that are Between 2 elements。但在我的具体情况下,html 可能会有所不同,并且我无法使用第二个元素的文本

基本上我有这样的结构:

<h1>Account Information</h1>
<a class="null" href="http:...">Remarks</a>
<a class="null" href="http:...">Owner Information</a>
<b>Account Detail</b>
<a class="null" href="http:...">Industrial</a>

<a class="null" href="http:...">land</a>
<b >Transfers</b>
<a class="null" href="http:...">11111</a>
<a class="null" href="http:...">22222</a>
Run Code Online (Sandbox Code Playgroud)

所以我想<a>在 b='Account Detail' 和下一个可以改变文本的 b 之间获取。

对于这种情况,我使用了上面问题的第二个答案的版本

//a[preceding-sibling::b='Account Detail' and following-sibling::b]
Run Code Online (Sandbox Code Playgroud)

对于这种情况,工作正常,因为我得到的 b='Account Detail' 之后只有一个 b

[工业、土地]

<b>但是如果b='Account Detail' 之后有多个

但是如果我们有多个<b>

<h1>Account Information</h1>
<a class="null" href="http:...">Remarks</a>
<a class="null" href="http:...">Owner Information</a>
<b>Account Detail</b>
<a class="null" href="http:...">Industrial</a>    
<a class="null" href="http:...">land</a>
<b class="">Permits</b>
 <a class="null" href="http:...">12-12-222</a>
 <a class="null" href="http:...">22-2-22</a>
<b >Transfers</b>
<a class="null" href="http:...">11111</a>
<a class="null" href="http:...">22222</a>
Run Code Online (Sandbox Code Playgroud)

结果是:

[工业、土地、12-12-222,22-2-22]

这不是期望的行为

有什么建议吗?提前致谢

And*_*son 4

尝试下面的 XPath 来获取所需的节点:

//a[preceding-sibling::b[1]='Account Detail' and following-sibling::b]
Run Code Online (Sandbox Code Playgroud)

preceding-sibling::b[1]='Account Detail'打算获取在有内容<b>的锚点之前没有前向兄弟姐妹的锚点'Account Detail'