本帖最后由 月牙丫里 于 2018-3-24 13:24 编辑
重新上传一下代码,迫切需要大佬们的解惑,谢谢。
city = {
'北京'='101010100',
'广州'='101280101',
'上海'='101020100'
}
import pickle
pickle_file = open('city_data.pkl','wb')
pickle.dump(city,pickle_file)
pickle_file.close()
import urllib.request
import json
import pickle
pickle_file = open('city_data.pkl','rb')
city = pickle.load(pickle_file)
password = input('请输入城市:')
name1 = city[password]
print(name1)
File1 = urllib.request.urlopen('http://www.weather.com.cn/weather1d/' + name1 +'.shtml#search')
print(File1)
weatherHTML = File1.read().decode('utf-8')#读入打开的ur1
print(weatherHTML)
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('按任意键退出')
|