设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 10033|回复: 1
打印 上一主题 下一主题

【Python 第44课】 输出没有该城市

[复制链接]

1

主题

0

好友

11

积分

新手上路

Rank: 1

跳转到指定楼层
楼主
发表于 2016-7-19 11:14:40 |显示全部楼层 |倒序浏览
源代码
# -*- coding: utf-8 -*-
import urllib2
import json
from city import city

cityname=raw_input('你想查询哪个城市天气?\n')

citycode=city.get(cityname)
print citycode
if citycode:
        url=('http://www.weather.com.cn/weather1d/%s.shtml#input'%citycode)
        content=urllib2.urlopen(url).read()
        print content
else:
        print'no this city'
运行结果:
你想查询哪个城市天气?
南京
None
no this city


个人感觉是中文参数的原因,但具体也不太清楚到底是不是,请老师指点
回复

使用道具 举报

1

主题

0

好友

11

积分

新手上路

Rank: 1

沙发
发表于 2016-7-20 19:58:02 |显示全部楼层
感谢老师,现在可以了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-5 05:49 , Processed in 0.035212 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部