爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 6986|回复: 0

[求助] 新手查天气代码到底哪一步错了?

[复制链接]

新浪微博达人勋

发表于 2017-3-15 14:17:00 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
import urllib2
import json
a=open('city.txt')
lines=a.readlines()
a.close()
cityname=raw_input('你想查那个城市的天气?\n')
kk=''
kk+=cityname
print kk
for line in lines:
    try:
        name=line.split(':')[0]
        if name=='kk':
            code=line.split(':')[1]
            print code
            break
    except:
        print 'error'
try:
    url=('http://www.weather.com.cn/data/cityinfo/%s.html'%code)
    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'失败'

2.png
1.png
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表