|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
大神帮帮忙看看,困扰好多天了就是不知道错哪了,代码如下:
import urllib.request
import json
city = {
'北京':'101010100',
'海淀':'101010200',
'朝阳':'101010300',
'顺义':'101010400',
'怀柔':'101010500',
'通州':'101010600',
'延庆':'101010800',
'石景山':'101011000',
'大兴':'101011100',
'房山':'101011200',
'密云':'101011300',
'门头沟':'101011400',
'平谷':'101011500',
'八达岭':'101011600',
'佛爷顶':'101011700',
'汤河口':'101011800',
'密云上甸子':'101011900',
'斋堂':'101012000',
'霞云岭':'101012100',
}
password = input('请输入城市:')
name1 = city[password]
File1 = urllib.request.urlopen('http://m.weather.com.cn/data/101010100.html')
weatherHTML = File1.read().decode('utf-8')
weatherJSON = json.JSONDecoder().decode(weatherHTML)
weatherInfo = weatherJSON['weatherinfo']
print('城市:',weatherInfo['city'])
print('时间:',weatherInfo['date_y'])
print('24小时天气:')
print('温度:',weatherInfo['temp1'])
print('天气:',weatherInfo['weather1'])
print('风速:',weatherInfo['wind1'])
print('紫外线:',weatherInfo['index_uv'])
print('穿衣指数:',weatherInfo['index_d'])
print('48小时天气:')
print('温度:',weatherInfo['temp2'])
print('天气:',weatherInfo['weather2'])
print('风速:',weatherInfo['wind2'])
print('紫外线:',weatherInfo['index48_uv'])
print('穿衣指数:',weatherInfo['index48_d'])
print('72小时天气:')
print('温度:',weatherInfo['temp3'])
print('天气:',weatherInfo['weather3'])
print('风速:',weatherInfo['wind3'])
input('按任意键退出:')
你看看那个网址,为什么不能用,这个代码执行没有错误,但是一输入城市就报错,
|
|