# 在dos命令下输入:python36 test.py 上海 import json, requests, sys # Compute location from command line arguments. # if len(sys.argv) < 2: # print('Usage: quickWeather.py location') # sys.exit() # location = ''.join(sys.argv[1:]) location = '上海' # Download the JSON data from wthrcdn.etouch.cn's API url ='http://wthrcdn.etouch.cn/weather_mini?city=%s' % (location) response = requests.get(url) response.raise_for_status() # Load JSON data into a Python variable. weatherData = json.loads(response.text) # print(response.text) # Print weather descriptions. w = weatherData['data'] print(w) print('Current weather in %s:' % (location)) print(w['forecast'][0]['low'])#输出今天的最低气温
第14章项目:获取的上海当前天气数据
最新推荐文章于 2024-04-16 00:05:50 发布