如果返回的数据是JSON格式的,我们可以用JSON提取器来提取需要的字段,这样更简单一点
-
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
返回的数据格式:
{"code":200,"data":{"numFound":5679,"numTotal":1000,"results":[{"applyType":"1","updateDate":"2019-02-18 08:59:47","refreshMulscore":"0.0","g_sort":"sort-ps-score-ranking-keyword","endDate":"2019-03-20 08:59:47","city":{"display":"深圳-南山区","items":[{"code":"765","name":"深圳"},{"code":"2039","name":"南山区"}]},"showLicence":0,"saleType":100,"positionURL":"https://jobs.zhaopin.com/CC120837247J00254874105.htm","g_weight":101,"industry":"160000,160400, 300100, 160200","welfare":["五险一金","周末双休","绩效奖金","全勤奖","带薪年假"],"salary":"8K-16K","SOU_POSITION_ID":"CC120837247J00254874105","duplicated":0,"geo":{"lon":"113.937987","lat":"22.523392"},"score":20.695484,"number":"CC120837247J00254874105","vipLevel":1003,"recruitCount":1,"workingExp":{"code":"510","name":"5-10年"},"companyScore":0,"tagIntHighend":0,"company":{"number":"CZ120837240","size":{"code":"3","name":"100-499人"},"name":"深圳市利谱信息技术有限公司","type":{"code":"5","name":"民营"},"url":"https://company.zhaopin.com/CZ120837240.htm"},"seo":"0","jobType":{"display":"IT质量管理/测试/配置管理,软件测试","items":[{"code":"160400","name":"IT质量管理/测试/配置管理"},{"code":"695","name":"软件测试"}]},"g_query":"query-ps-score-1","resumeCount":46,"createDate":"2019-02-18 08:59:47","jobName":"中高级测试工程师","manualScore":"0.0","eduLevel":{"code":"4","name":"本科"},"companyLogo":"","futureJob":false,"emplType":"全职","g_source":"source-solr-position","SOU_POSITION_SOURCE_TYPE":1,"recentAndTotal":{"applyTotal":"46","exposureTotal":"2350","clickTotal":"231","exposureRecent":"0","clickRecent":"0","applyRecent":"0"},"tags":[],"businessArea":"科技园","positionLabel":"{"qualifications":null,"chatWindow":20,"jobLight":["五险一金","周末双休","绩效奖金","全勤奖","带薪年假","弹性工作","节日福利","员工旅游"],"role":null,"companyTag":null,"level":null,"refreshLevel":0,"skill":["应用底层 ","熟悉网路知识","软件功能测试","网络设备测试"]}","expandCount":0,"jobTag":{"searchTag":"应用底层 ,熟悉网路知识,软件功能测试,网络设备测试,五险一金,周末双休,绩效奖金,全勤奖,带薪年假,弹性工作,节日福利,员工旅游"},"feedbackRation":0.4557,"interview":0,"selected":false,"applied":false,"collected":false,"isShow":false,"timeState":"最新","rate":""},{"applyType":"1","updateDate":"2019-02-18 14:02:38","refreshMulscore":"0.0","g_sort":"sort-ps-score-ranking-keyword","endDate":"2019-03-13 14:55:38","city":{"display":"深圳","items":[{"code":"765","name":"深圳"}]},"showLicence":0,"saleType":100,"positionURL":"https://jobs.zhaopin.com/CC143316927J00059803005.htm","g_weight":101,"industry":"160400,160000,180000","welfare":["五险一金","员工旅游","加班补助","交通补助","餐补"],"salary":"6K-10K","SOU_POSITION_ID":"CC143316927J00059803005","duplicated":0,"geo":{"lon":"114.070226","lat":"22.556923"},"score":20.717499,"number":"CC143316927J00059803005","vipLevel":1003,"recruitCount":3,"workingExp":{"code":"103","name":"1-3年"},"companyScore":0,"tagIntHighend":0,"company":{"number":"CZ143316920","size":{"code":"5","name":"1000-9999人"},"name":"深圳市赢时胜信息技术股份有限公司","type":{"code":"5","name":"民营"},"url":"https://company.zhaopin.com/CZ143316920.htm"},"seo":"0","jobType":{"display":"IT质量管理/测试/配置管理,软件测试","items":[{"code":"160400","name":"IT质量管理/测试/配置管理"},{"code":"695","name":"软件测试"}]},"g_query":"query-ps-score-1","resumeCount":68,"createDate":"2019-02-11 14:55:38","jobName":"测试工程师","manualScore":"0.0","eduLevel":{"code":"4","name":"本科"},"companyLogo":"","futureJob":false,"emplType":"全职","g_source":"source-solr-position","SOU_POSITION_SOURCE_TYPE":1,"recentAndTotal":{"applyTotal":"68","exposureTotal":"3698","clickTotal":"218","exposureRecent":"0","clickRecent":"0","applyRecent":"0"},"tags":[],"businessArea":"莲花一村","positionLabel":"{"qualifications":null,"chatWindow":10,"jobLight":["五险一金","员工旅游","加班补助","交通补助","餐补","通讯补助"],"role":null,"companyTag":null,"level":null,"refreshLevel":1,"skill":null}","expandCount":0,"jobTag":{"searchTag":"五险一金,员工旅游,加班补助,交通补助,餐补,通讯补助"},"feedbackRation":0.1269,"interview":0,"selected":false,"applied":false,"collected":false,"isShow":false,"timeState":"最新","rate":""}],"debugInfo":null,"loginfo":null,"facets":[],"extend":"","method":"","taskId":"0a58fc153a9f4fcc9ccefd399e079156","scores":null,"elapsed":["gateway 内部执行耗时117毫秒","gateway 调用总耗时0毫秒","psapi 共耗时135毫秒"],"time":"2019-02-18 18:34:18"}}
现在我们来提取职位的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] |
数组切片运算符 |
?() |
支持过滤操作 |
() |
支持表达式计算 |