嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
爬取天气预报信息并展示
def get_weather_data() :#获取网站数据
city_name = enter.get()#获取输入框的内容
url1 = 'http://wthrcdn.etouch.cn/weather_mini?city=' urllib.parse.quote(city_name)
weather_data = urllib.request.urlopen(url1).read()
#读取网页数据
weather_data = gzip.decompress(weather_data).decode('utf-8')
#解压网页数据
weather_dict = json.loads(weather_data)
#将json数据转换为dict数据
if weather_dict.get('desc') == 'invilad-citykey':
messagebox.showerror("提示","你输入的城市名有误,或者天气中心未收录你所在城市")
else:
#print(messagebox.askokcancel('xing','bingguo'))
show_data(weather_dict,city_name)