鱼C论坛

 找回密码
 立即注册
查看: 1696|回复: 5

为啥会报错呢

[复制链接]
发表于 2021-7-22 19:34:01 | 显示全部楼层 |阅读模式

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

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

x
微信图片_20210722193321.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-7-22 20:32:36 | 显示全部楼层
发送代码和文件,还有json的内容
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-7-22 20:33:04 | 显示全部楼层
代码放一下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-7-22 21:28:56 | 显示全部楼层

import pickle
import urllib.request
import json

pickle_file = open("ciyt_data.pkl", 'rb')
city = pickle.load(pickle_file)

password = input('请输入城市:')
name1 = city[password]
File1 = urllib.request.urlopen('http://m.weather.com.cn/data/'+name1+'.html')#打开url
weatherHTML = File1.read().decode("utf-8")#读入打开的url
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'])
input ('按任意键退出:')
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-7-22 21:33:49 | 显示全部楼层
xiaosi4081 发表于 2021-7-22 20:32
发送代码和文件,还有json的内容
  1. import pickle
  2. import urllib.request
  3. import json

  4. pickle_file = open("ciyt_data.pkl", 'rb')
  5. city = pickle.load(pickle_file)

  6. password = input('请输入城市:')
  7. name1 = city[password]
  8. File1 = urllib.request.urlopen('http://m.weather.com.cn/data/'+name1+'.html')#打开url
  9. weatherHTML = File1.read().decode("utf-8")#读入打开的url
  10. weatherJSON = json.JSONDecoder().decode(weatherHTML)#创建json
  11. weatherInfo = weatherJSON["weatherinfo"]
  12. #打印信息
  13. print ( '城市:', weatherInfo['city'])
  14. print ('时间:', weatherInfo['date_y'])
  15. print ( '24小时天气:')
  16. print ('温度:', weatherInfo['temp1'])
  17. print ('天气:', weatherInfo['weather1'])
  18. print ('风速:', weatherInfo['wind1'])
  19. print ('紫外线:', weatherInfo['index_uv'])
  20. print ('穿衣指数:', weatherInfo['index_d'])
  21. print ('48小时天气:')
  22. print ('温度:', weatherInfo['temp2'])
  23. print ('天气:', weatherInfo['weather2'])
  24. print ('风速:', weatherInfo['wind2'])
  25. print ('紫外线:', weatherInfo['index48_uv'])
  26. print ('穿衣指数:', weatherInfo['index48_d'])
  27. print ('72小时天气:')
  28. print ('温度:', weatherInfo['temp3'])
  29. print ('天气:', weatherInfo['weather3'])
  30. print ('风速:', weatherInfo['wind3'])
  31. input ('按任意键退出:')
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-7-22 21:40:00 | 显示全部楼层

11

11.zip

45.42 KB, 下载次数: 0

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-27 00:15

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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