自己用到的xpath都收集下咯!!!
持續更新本頁面
xpath匹配包含字符
contains
xpath('//div[contains(@class,"xxx")]')
xpath匹配去除空格
normalize-space
xpath('normalize-space(//div[@class="xxx"])')
xpath匹配以什么開始
xpath('starts-with(@name,"xxx")')
xpath中使用正則表達式
xpath(r'//*[re:match(@id,"img_\d+")]', namespaces={"re": "http://exslt.org/regular-expressions"})
xpath獲取父節點
parent::a
xpath('./a/span[@class="refinement-category"]/parent::a/@href')
xpath 相對節點查找
獲取當前節點的所有父節點或者祖父節點
xpath('./ancestor::*')
獲取當前節點的所有先輩節點以及本身
xpath('./ancestor-or-self::*')
獲取當前節點所有屬性
xpath('./attribute::*')
查找當前節點的所有子節點
xpath('./child::*')
獲取當前節點的所有后代節點
xpath('./descendant::*')
獲取當前節點結束標簽后的所有節點
xpath('./following::*')
獲取當前節點的下一個兄弟節點
xpath('./following-sibing::*')
獲取當前節點的父節點
xpath('./parent::*')
獲取當前節點開始標簽前的所有節點
xpath('./preceding::*')
獲取當前節點的上一個兄弟節點
xpath('./preceding-sibing::*')
選取當前節點
xpath('./self::*')
獲取當前節點的父節點的某個屬性值是否存在
xpath('//div[text()="Import"]/../self::*[@tabin="0"]')