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')