标签:
通过中国天气网的通用接口查询天气。
#coding:utf-8 import urllib2, json from city import city yourcity = raw_input("你想查那个城市的天气?") #yourcity = ‘杭州‘ url = "http://www.weather.com.cn/data/cityinfo/" + city[yourcity] + ".html" response = urllib2.urlopen(url, timeout=10) city_dict = response.read() jsondata = json.JSONDecoder().decode(city_dict) print jsondata temp_low = jsondata[‘weatherinfo‘][‘temp1‘] print temp_low temp_high = jsondata[‘weatherinfo‘][‘temp2‘] weather = jsondata[‘weatherinfo‘][‘weather‘] print weather print temp_low + "~" + temp_high
标签:
原文地址:http://www.cnblogs.com/wangjibo/p/4184242.html