xpath學(xué)習(xí)筆記

xpath學(xué)習(xí)

#/(根節(jié)點(diǎn))

/bookstore

/bookstore/book/

/bookstore/book/author? div/div/div/div/input/a

//忽略根節(jié)點(diǎn)

//author???所有作者???????????? //a會(huì)找多

//book???所有書(shū)

//price/a/b//c忽略中間節(jié)點(diǎn)

//price?所有價(jià)格


謂語(yǔ)

//book[1] 第一本書(shū)

//book[2] 第二本書(shū)

//book[last()] 最后一本書(shū)

//book[last()-1] 倒數(shù)第二本


[]前加@表示屬性

//book[@category="cooking"]

//book[@cover]


Href = 百度地址的一個(gè)鏈接

//a[@href =’https://www.baidu.com/’]


找名字叫J K. Rowling的作者

//author[text()=‘J K. Rowling’]


找名字叫J K. Rowling的書(shū)的定價(jià)

//author[text()=‘J K. Rowling’]/../price


#找定價(jià)大于35的書(shū)的作者

//price[text()]>35/../author


and

or

not


//

1.選取書(shū)店里所有書(shū)的詳細(xì)信息

//book

2.選取所有書(shū)的標(biāo)題,所有書(shū)的分類(lèi)

//title?//book/@category???.get_attribut('category')

3.選取第一本書(shū)的定價(jià)

//book[1]/price

4.選取最后一本書(shū)的作者

//book[last()]/author

5.選取倒數(shù)第二本書(shū)的分類(lèi)

//book[last()-1]/@category

6.選取包含cover屬性的書(shū)的標(biāo)題

//book[@cover]/title

7.選取定價(jià)高于35的書(shū)的標(biāo)題

//price[text()]>35/../title

8.選取定價(jià)在30到40之間的書(shū)的標(biāo)題

//price[text()>=30 and text()<=40]/../title

9.選取作者多于一個(gè)的書(shū)的標(biāo)題

//book[count(author)>1]/title

10.選取作者多于一個(gè)的書(shū)只列出所有作者名

//book[count(author)>1]/author/text()

11.選取分類(lèi)不是web 且價(jià)格低于40的書(shū)的作者

//book[@category!='web' and

price<40]/author

12.選取標(biāo)題名稱(chēng)包含X的所有書(shū)的定價(jià)值

//title[contains(text(),'x')/../price/text()

start-with(text(),'x')

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容