Python获取城市天气,
2021/9/7 22:07:53
本文主要是介绍Python获取城市天气,,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
实现代码
因此实现代码就可以写出来了!只需要获取网页中的元组数据。
weather.py
#coding:utf-8 from urllib.parse import urlencode import requests import urllib import json#处理网页数据 while True:#循环 message = str(input("要查询的城市:")) url="https://api.iyk0.com/tq/?city={}".format(message)#获取用户输入的城市进行查询 request=url re=requests.get(request) rep = re.json() ''' 获取网页中的响应的元组变量 ''' code = rep.get('code') msg = rep.get('msg') city = rep.get('city') up = rep.get('update_time') wea = rep.get('wea') wea_img = rep.get('wea_img') tem = rep.get('tem') tem_day = rep.get('tem_day') tem_night = rep.get('tem_night') win = rep.get('win') win_speed = rep.get('win_speed') win_meter = rep.get('win_meter') air = rep.get('air') time = rep.get('time') print('\n城市名字:',city) print('更新时间:',up) print('天气情况:',wea) print('时实温度:',tem) print('高温:',tem_day) print('低温:',tem_night) print('风向:',win) print('风力等:',win_speed) print('风速:',win_meter) print('空气质量:',air) print('当天日期,星期:',time,'\n') lis = {'code':code, 'msg':msg, 'city':city, 'update_time':up, 'wea':wea, 'wea_img':wea_img, 'tem':tem, 'tem_day':tem_day, 'win':win, 'win_speed':win_speed, 'win_meter':win_meter, 'air':air, 'time':time, } #print(lis)
这篇关于Python获取城市天气,的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-28Python编程基础教程
- 2024-12-27Python编程入门指南
- 2024-12-27Python编程基础
- 2024-12-27Python编程基础教程
- 2024-12-27Python编程基础指南
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型
- 2024-12-23使用python部署一个usdt合约,部署自己的usdt稳定币
- 2024-12-20Python编程入门指南