鱼C论坛

 找回密码
 立即注册
查看: 1450|回复: 1

关于查询天气的问题

[复制链接]
发表于 2018-3-12 23:26:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
运行这段代码后
import urllib.request
import json
import pickle
pickle_file = open('city_data.pkl','rb')
city = pickle.load(pickle_file)


password = input('请输入城市:')
name1 = city[password]
File1 = urllib.request.urlopen('http://www.weather.com.cn/data/' + name1 +'.htm1')
weatherHTML = File1.read().decode('utf-8')#读入打开的ur1
weatherJSON = json.JSONDecoder().decode(weatherHTML)#创建json
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'])
#print('紫外线:',weatherInfo['index72_uv'])
#print('穿衣指数:',weatherInfo['index72_d'])
input('按任意键退出')



出现下面的错误的原因是什么(我的是python3.4.1版本)

请输入城市:汕头
Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\Weather\天气查询.py", line 12, in <module>
    weatherJSON = json.JSONDecoder().decode(weatherHTML)#创建json
  File "C:\Python34\lib\json\decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-3-13 10:42:19 | 显示全部楼层
你可以试一下换个城市,不知道是缺少城市信息,还是其他原因
最好按照代码格式发一下,好复制粘贴,好修改
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-28 13:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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