import requests import json city_name=input('请输入城市') url='http://api.map.baidu.com/telematics/v3/weather?location=%s&output=json&ak=TueGDhCvwI6fOrQnLM0qmXxY9N0OkOiQ&callback=?'%city_name rs=requests.get(url) print(rs) rs_dict=json.loads(rs.text) error_code=rs_dict['error'] if error_code==0: results=rs_dict['results'] info_dict=results[0] city_name=info_dict['currentCity'] pm=info_dict['pm25'] print('当前城市:%s 当前pm:%s'%(city_name,pm)) weather_date=info_dict['weather_data'] for wether_dict in weather_date: date=wether_dict['date'] weather=wether_dict['weather'] wind=wether_dict['wind'] temperature=wether_dict['temperature'] print('日期:%s天气:%s风:%s温度:%s'%(date,weather,wind,temperature))
天气查询
最新推荐文章于 2020-08-21 20:44:35 发布