这是一个创建于 3699 天前的主题,其中的信息可能已经有所发展或是发生改变。
始终无法查到天气,返回“没有找到该城市”。好像是无法读取city中的json信息的原因,printcitycode返回“None”。。。求解啊,代码如下
# -*- coding: utf-8 -*-
import urllib2
import json
from city import city
cityname = raw_input('你想查哪个城市的天气?\n')
citycode = city.get(cityname)
if citycode:
try:
url = ('http://www.weather.com.cn/data/cityinfo/%s.html'
% citycode)
content = urllib2.urlopen(url).read()
data = json.loads(content)
result = data['weatherinfo']
str_temp = ('%s\n%s ~ %s') % (
result['weather'],
result['temp1'],
result['temp2']
)
print str_temp
except:
print '查询失败'
else:
print '没有找到该城市'
2 条回复 • 2014-08-12 17:22:23 +08:00
|
|
1
mengskysama 2014-08-12 17:14:00 +08:00
而且你这个接口也失效了············
|