- 帖子
- 4
- 精华
- 0
- 积分
- 44
- 阅读权限
- 10
- 注册时间
- 2016-10-7
- 最后登录
- 2017-7-22
|
# -*- coding:cp936 -*-
import urllib.request
import json
from city import city
cityname = input('你想查询哪个城市?\n')
citycode = city.get(cityname)
if citycode:
try:
url = ('http://wthrcdn.etouch.cn/weather_mini?citykey=%s'%citycode)
content = urllib.request.urlopen(url).read()
data = json.loads(content.decode('utf-8'))
result = data['weatherinfo']
str_temp = ('%s\n%s~%s')%(
result['weather'],
result['temp1'],
result['temp2']
)
print(str_temp)
except:
print('查询失败')
else:
print('你所查询的城市不存在!')
老师,更换网址后显示查询失败,是什么回事呢?网址不对? |
|