- 帖子
- 2
- 精华
- 0
- 积分
- 15
- 阅读权限
- 10
- 注册时间
- 2016-7-14
- 最后登录
- 2017-2-9
|
你好,按照课程中代码运行后,输出一直是 没有找到该城市。是什么地方出问题了呢?
=======================================
# -*- coding: cp936 -*-
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("没有找到该城市")
========================================== |
|