本文主要是介绍python调用天气接口并解析json数据,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
"""
使用python调用请求
使用pip install requests安装requests
"""
import jsonimport requestsresp = requests.get(url='https://apis.tianapi.com/tianqi/index',params={'key': '4a9ce7c2516a223ewe323dwe323ew323eq1', 'city': '101020100', 'type': 1}
)
dict = json.loads(resp.text)
print(dict)
new_dict = dict['result']
print(new_dict)
date = new_dict['date']
week = new_dict['week']
print(date)
print(week)
这篇关于python调用天气接口并解析json数据的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!