python reques库示例代码
import requests import jsonpath import unittest api_url = 'http://apis.juhe.cn/mobile/get' params_dict = { "phone": "17710181598", # 查询天气的城市名称,如:北京、苏州、上海 "key": "7f7302a1f7f4a89718d553a70e038b6c", # 您申请的接口API接口请求Key "dtype": "json", # 您申请的接口API接口请求Key } # 返回对象res res=requests.get(api_url,params=params_dict) res=res.json() print(res) province=jsonpath.jsonpath(res,'$.result.province') print(province) company=jsonpath.jsonpath(res,'$.result.company') company="".join(company) province="".join(province) expctvalue="Return Successd!" print("省份是{},公司是{}".format(province,company))
jiapengchu
posted on 2021-12-11 18:55 jiapengchu 阅读(38) 评论(0) 编辑 收藏 举报