如果返回的数据是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] |
数组切片运算符 |
?() |
支持过滤操作 |
() |
支持表达式计算 |