1 import requests 2 import json 3 4 weatherinfo_search = 'https://restapi.amap.com/v3/weather/weatherInfo?parameters' 5 params = {'key':'c23b11e80ffac05211196aa0kl', 6 'city':'110113', 7 'extensions':'base', 8 'output':'JSON'} 9 result = requests.get(url=weatherinfo_search,params=params) 10 print(result.status_code) 11 print(result.json()) 12 print(result.json()["count"]) 13 print(result.text) 14 print(result.text[0]) 15 print(json.dumps(result.json(),sort_keys=True,indent=4,ensure_ascii=False))
#ensure_ascii=False不添加则中文会产生乱码
#输出格式为:
{
"count": "1",
"info": "OK",
"infocode": "10000",
"lives": [
{
"adcode": "110113",
"city": "东城区",
"humidity": "23",
"province": "北京",
"reporttime": "2021-05-07 22:39:03",
"temperature": "22",
"weather": "浮尘",
"winddirection": "西南",
"windpower": "5"
}
],
"status": "1"
}
Process finished with exit code 0
###################################################################
title = '1'
name = '2'
msg = f'''----------{title}----------
name : {name}
'''
print(msg)