如果返回的數據是JSON格式的,我們可以用JSON提取器來提取需要的字段,這樣更簡單一點,
老司機你懂的:https://item.taobao.com/item.htm?id=613711271112
JSON主要運用於返回JSON格式的,格式:$.data[0].id $.data.xx1。
提取器要放到http請求下面:
-
Variable names:保存的變量名,后面使用${Variable names}引用
-
JSON Path expressions:調試通過的json path表達式
-
Match Numbers:匹配數字(0代表隨機,1代表第一個,-1代表所有)
-
Default Values:找不到時默認值,一般設置為NOT FOUND
-
Compute concatenation var(suffix_ALL):是否統計所有,即將匹配到的所有值保存,名為“變量名_ALL”
示例:
請求URL:https://fe-api.zhaopin.com/c/i/sou?pageSize=60&cityId=765&workExperience=-1&education=-1&companyType=-1&employmentType=-1&jobWelfareTag=-1&kw=%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95&kt=3
返回的數據格式:
"recordsFiltered": 8,
"data": [
{
"thisYear": 0,
"hfyljg": "廣州市養老機構",
"updateDate": null,
"ysq2": null,
"con": null,
"ysq3": null,
"dpid": null,
"ztpf": "A(優秀)",
"createdate": null,
"delFlag": "0",
"hfrq": "2019-11-26 00:00:00",
"hfgcyxzl": "",
"createby": null,
"updatedate": null,
"updateBy": null,
"ysq": null,
"id": "7695969a08c34ff18ee847437c295377",
"hfjlr": "市領導",
"isdel": null,
"createDate": null,
"createtime": null,
"message": null,
"fwtd": "A(優秀)",
"hfgcsm": "test",
"createBy": null,
"fwzl": "A(優秀)",
"hflr": "test",
"updateby": null,
"rzlrmyd": "A(優秀)",
"qtsmbz": "",
"qcode": null,
"remarks": null
},
{
"thisYear": 0,
"hfyljg": "廣州市養老機構",
"updateDate": null,
"ysq2": null,
"con": null,
"ysq3": null,
"dpid": null,
"ztpf": "A(優秀)",
"createdate": null,
"delFlag": "0",
"hfrq": "2019-11-26 00:00:00",
"hfgcyxzl": "",
"createby": null,
"updatedate": null,
"updateBy": null,
"ysq": null,
"id": "7ef39120839641509a448022d8d19f1d",
"hfjlr": "市領導",
"isdel": null,
"createDate": null,
"createtime": null,
"message": null,
"fwtd": "A(優秀)",
"hfgcsm": "test",
"createBy": null,
"fwzl": "A(優秀)",
"hflr": "test",
"updateby": null,
"rzlrmyd": "A(優秀)",
"qtsmbz": "",
"qcode": null,
"remarks": null
},
{
"thisYear": 0,
"hfyljg": "增城區中新鎮福和敬老院",
"updateDate": null,
"ysq2": null,
"con": null,
"ysq3": null,
"dpid": null,
"ztpf": "C(一般)",
"createdate": null,
"delFlag": "0",
"hfrq": "2019-12-10 00:00:00",
"hfgcyxzl": "4c698efd8744f5d4319bfc5d7a5d36c1",
"createby": null,
"updatedate": null,
"updateBy": null,
"ysq": null,
"id": "b0b9fcd09b01495a82f21cddd02dd2d0",
"hfjlr": "市領導",
"isdel": null,
"createDate": null,
"createtime": null,
"message": null,
"fwtd": "B(良好)",
"hfgcsm": "我很好",
"createBy": null,
"fwzl": "B(良好)",
"hflr": "國家戰士",
"updateby": null,
"rzlrmyd": "B(良好)",
"qtsmbz": "沒問題",
"qcode": null,
"remarks": null
},
{
"thisYear": 0,
"hfyljg": "增城區中新鎮福和敬老院",
"updateDate": null,
"ysq2": null,
"con": null,
"ysq3": null,
"dpid": null,
"ztpf": "C(一般)",
"createdate": null,
"delFlag": "0",
"hfrq": "2019-12-10 00:00:00",
"hfgcyxzl": "4c698efd8744f5d4319bfc5d7a5d36c1",
"createby": null,
"updatedate": null,
"updateBy": null,
"ysq": null,
"id": "2576d5940acb48e1a55ddb56fd28e34f",
"hfjlr": "市領導",
"isdel": null,
"createDate": null,
"createtime": null,
"message": null,
"fwtd": "B(良好)",
"hfgcsm": "我很好",
"createBy": null,
"fwzl": "B(良好)",
"hflr": "國家戰士",
"updateby": null,
"rzlrmyd": "B(良好)",
"qtsmbz": "沒問題",
"qcode": null,
"remarks": null
},
{
"thisYear": 0,
"hfyljg": "增城區中新鎮福和敬老院",
"updateDate": null,
"ysq2": null,
"con": null,
"ysq3": null,
"dpid": null,
"ztpf": "C(一般)",
"createdate": null,
"delFlag": "0",
"hfrq": "2019-12-10 00:00:00",
"hfgcyxzl": "4c698efd8744f5d4319bfc5d7a5d36c1",
"createby": null,
"updatedate": null,
"updateBy": null,
"ysq": null,
"id": "a9aafaa9c64a419c8eabae370f0dae31",
"hfjlr": "市領導",
"isdel": null,
"createDate": null,
"createtime": null,
"message": null,
"fwtd": "B(良好)",
"hfgcsm": "我很好",
"createBy": null,
"fwzl": "B(良好)",
"hflr": "國家戰士",
"updateby": null,
"rzlrmyd": "B(良好)",
"qtsmbz": "沒問題",
"qcode": null,
"remarks": null
},
{
"thisYear": 0,
"hfyljg": "增城區中新鎮福和敬老院",
"updateDate": null,
"ysq2": null,
"con": null,
"ysq3": null,
"dpid": null,
"ztpf": "C(一般)",
"createdate": null,
"delFlag": "0",
"hfrq": "2019-12-10 00:00:00",
"hfgcyxzl": "4c698efd8744f5d4319bfc5d7a5d36c1",
"createby": null,
"updatedate": null,
"updateBy": null,
"ysq": null,
"id": "b64df74269cd4805a70fdd0b0b4a8cf9",
"hfjlr": "市領導",
"isdel": null,
"createDate": null,
"createtime": null,
"message": null,
"fwtd": "B(良好)",
"hfgcsm": "我很好",
"createBy": null,
"fwzl": "B(良好)",
"hflr": "國家戰士",
"updateby": null,
"rzlrmyd": "B(良好)",
"qtsmbz": "沒問題",
"qcode": null,
"remarks": null
},
{
"thisYear": 0,
"hfyljg": "中二機構",
"updateDate": null,
"ysq2": null,
"con": null,
"ysq3": null,
"dpid": null,
"ztpf": "C(一般)",
"createdate": null,
"delFlag": "0",
"hfrq": "2019-08-04 00:00:00",
"hfgcyxzl": "",
"createby": null,
"updatedate": null,
"updateBy": null,
"ysq": null,
"id": "c22175d30d7141248054a6a5db3618e3",
"hfjlr": "白雲區經辦",
"isdel": null,
"createDate": null,
"createtime": null,
"message": null,
"fwtd": "C(一般)",
"hfgcsm": "一般",
"createBy": null,
"fwzl": "C(一般)",
"hflr": "劉賢",
"updateby": null,
"rzlrmyd": "C(一般)",
"qtsmbz": "",
"qcode": null,
"remarks": null
},
{
"thisYear": 0,
"hfyljg": "中四機構",
"updateDate": null,
"ysq2": null,
"con": null,
"ysq3": null,
"dpid": null,
"ztpf": "A(優秀)",
"createdate": null,
"delFlag": "0",
"hfrq": "2019-08-02 00:00:00",
"hfgcyxzl": "",
"createby": null,
"updatedate": null,
"updateBy": null,
"ysq": null,
"id": "23598ee7b0a140b49a84e96e8b63345d",
"hfjlr": "白雲區經辦",
"isdel": null,
"createDate": null,
"createtime": null,
"message": null,
"fwtd": "A(優秀)",
"hfgcsm": "老人對機構評價不錯",
"createBy": null,
"fwzl": "B(良好)",
"hflr": "黃佩",
"updateby": null,
"rzlrmyd": "B(良好)",
"qtsmbz": "",
"qcode": null,
"remarks": null
}
],
"draw": 0,
"recordsTotal": 8
}
現在我們來提取職位的positionURL字段:
1、在查看結果樹中通過JSON Path Tester來調試json path
2、添加JSON提取器,設置正確的參數,獲取第一個positionURL
輸出結果:
3、獲取所有的positionURL
輸出結果:
4、把所有的positionURL放到一個字段中
輸出結果:
5、一次性提取多個字段,比如我們要提取第一個職位的jobName;salary;positionURL三個字段
輸出結果:
Json Path表達式:
JsonPath |
描述 |
$ |
根節點 |
@ |
當前節點 |
.or[] |
子節點 |
.. |
選擇所有符合條件的節點 |
* |
所有節點 |
[] |
迭代器標示,如數組下標 |
[,] |
支持迭代器中做多選 |
[start:end:step] |
數組切片運算符 |
?() |
支持過濾操作 |
() |
支持表達式計算 |