我想在某個文本之后的元素中獲取文本,即。“預計收入增長”。我想得到值 18.10% 。我想遵循的模式是如上所述查找某個文本,然后獲取緊隨其后的 h2 元素之后的文本。
是否可以使用一個 xpath 運算式來同時執行這兩個步驟?
- 匹配特定文本“預計收入增長”的 div
- 直接跳轉到div外的h1元素(這里要跳兩個div才能到h1元素)
如何匹配文本并通過 xpath 到達下一個直接 h1 元素?
<div>
<div class="p small mb-8 box-label text-left text-blue-500">
<div class="tt-container">
<button aria-label="open tooltip" class="button link" type="button" role="tooltip" aria-expanded="false">
Projected earning growth
</button>
</div>
</div>
<h2 class="mb-8 text-left">18.10%</h2>
</div>
uj5u.com熱心網友回復:
如果我理解正確的,你想從去Projected earning growth到18.10%這是在H2標簽。不知道你為什么提到 h1 標簽。
//button[contains(text(),'Projected earning growth')]/../../following-sibling::h2
應該完成作業,
請注意,/..要在 HTMLDOM 中升級。
這是您遇到的問題的直接解決方案。
我還建議你看看xpath parent和ancestor.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/321717.html
