xpath 少見常用 兄弟節點 父子節點

    <div>
        <a id="1" href="www.baidu.com">我是第1個a標籤</a>
        <p>我是p標籤</p>
        <a id="2" href="www.baidu.com">我是第2個a標籤</a>
        <a id="3" href="www.baidu.com">我是第3個a標籤</a>
        <a id="4" href="www.baidu.com">我是第4個a標籤</a>
        <p>我是p標籤</p>
        <a id="5" href="www.baidu.com">我是第5個a標籤</a>
    </div>

獲取第三個a標籤的下一個a標籤:"//a[@id='3']/following-sibling::a[1]"

獲取第三個a標籤後面的第N個標籤:"//a[@id='3']/following-sibling::*[N]"

獲取第三個a標籤的上一個a標籤:"//a[@id='3']/preceding-sibling::a[1]"

獲取第三個a標籤的前面的第N個標籤:"//a[@id='3']/preceding-sibling::*[N]"

獲取第三個a標籤的父標籤:"//a[@id=='3']/.."
————————————————
版權聲明:本文爲CSDN博主「qq_37059367」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/qq_37059367/article/details/83819828

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章