首页 > 其他 > 详细

通过中国天气网的通用接口查询天气

时间:2014-12-25 12:38:57      阅读:287      评论:0      收藏:0      [点我收藏+]

通过中国天气网的通用接口查询天气。

#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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!