Python
---小白121的记录笔记
天气预报
当天天气预报获取的api :
https://www.sojson.com/open/api/weather/json.shtml?city=南京
def weather_forecast(): '''需要调用requests, json''' url = 'https://www.sojson.com/open/api/weather/json.shtml?city=南京' req = requests.get(url).text html = json.loads(req) html_2 = html['data'] html_3 = html_2['forecast'] html_4 = html_3[0] data = ('%s\n%s\t\t%s\n%s\t\t%s' %(html_4['date'], html_4['high'], html_4['low'], html_4['type'], html_4['notice'])) return data
效果如上