jsonpath的基本语法:

python爬虫从0到1 - jsonpath_ajax


实例:

json值:

{ “store”: {
“book”: [
{ “category”: “reference”,
“author”: “Nigel Rees”,
“title”: “Sayings of the Century”,
“price”: 8.95
},
{ “category”: “fiction”,
“author”: “Evelyn Waugh”,
“title”: “Sword of Honour”,
“price”: 12.99,
“isbn”: “0-553-21311-3”
}
],
“bicycle”: {
“color”: “red”,
“price”: 19.95
}
}
}

输出book[0]的author值

"$.store.book[0].author"

输出全部author的值

"$.store.book[*].author"

输出book[*]中category == 'reference’的book

"$.store.book[?(@.category == 'reference')]"

输出book[*]中price>10的book

"$.store.book[?(@.price>10)]"

输出book[*]中含有isbn元素的book

"$.store.book[?(@.isbn)]"

输出该json中所有price的值

"$..price"

输出该json中所有title的值

"$..title"

输出该json中book 0,1的值

"$..book[0,1]"
#或者
"$..book[:2]"