3
我對此問題有類似的問題Xpath Get elements that are between 2 elements。但在我的特定情況下,HTML可以有所不同,就像我現在無法使用第二個元素的文本Xpath獲取介於2個元素之間的元素,我們無法使用標識或文本標識第二個標記
基本上我有一個結構:
<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>
所以我想在B ='賬戶之間得到<a>
細節「和下一個可以改變文字的b。
對於這個情況下,我使用的版本的2nd answer of question above
//a[preceding-sibling::b='Account Detail' and following-sibling::b]
這種情況下工作正常後因B =「帳戶資料」 我
[工業只有一架B ,土地]
但是,如果我們有不止一個<b>
後b ='帳戶詳細'
但是,如果我們有一個以上的<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>
結果是:
[工業,土地,12-12-222,22-2-22]
這不是所需的行爲
有什麼建議嗎? 由於事先
炒菜鍋確定之前沒有前一兄弟姐妹
<b>
錨,什麼是區別b [1]或b在這裏? – Cyberguille'b [1] ='帳戶明細'意味着*第一個*先前 - 兄弟'b'節點具有內容「帳戶明細」,因此在這種情況下,例如,「 12-12-222 '不會匹配,因爲這個錨點的第一個前同胞'b'具有內容''Permits'''。它實際上可以簡化爲'// a [before-sibling :: b [1] ='Account Detail']' – Andersson