python 天气预报获取
来源:互联网 发布:gentoo linux下载 编辑:程序博客网 时间:2024/06/14 05:42
通过对地名的编码获取,通过编码获取到天气信息
源码如下:
# -*- encoding: utf-8 -*-import urllib2from cityCode import cityimport jsonlocation = raw_input('请输入你需要查询的城市名字:')citycode=""# 城市编码获取try: citycode =city[location]except: print "not Found"url= "http://www.weather.com.cn/data/cityinfo/"+citycode+".html"#构造网址# 发起查询weather_json_string = urllib2.urlopen(url).read()# 结果分析weather = json.loads(weather_json_string)print weather# 结果打印print weather['weatherinfo']['city']print weather['weatherinfo']['ptime']print weather['weatherinfo']['cityid']print weather['weatherinfo']['temp2']print weather['weatherinfo']['temp1']print weather['weatherinfo']['weather']
运行结果截图:
阅读全文
0 0
- python获取天气预报
- python 天气预报获取
- python 获取省份的天气预报
- [Python]GUI编程练习 -- 获取天气预报
- 4行Python代码获取所在城市天气预报
- 获取天气预报
- 获取天气预报
- python天气预报
- python 天气预报
- Python 天气预报
- Python小工具——通过API获取天气预报
- [原创]获取天气预报信息
- 自动获取天气预报-----------------------------------------白晓哲
- 怎样实时获取天气预报
- 获取天气预报c#
- HttpUrlConnection 获取天气预报
- 免费获取天气预报代码
- Java获取yahoo天气预报
- 如何开发混合式app
- history.pushState的实际使用笔记
- 使用parallel-ssh批量执行远程shell命令
- 自适应陷波器
- Spark相关的英文参考
- python 天气预报获取
- QML使用C++定义的model
- 安卓开发知识框架_1_知识点总结
- Spring+EhCache缓存实例(详细讲解+源码下载)
- 记录一次 linux kernel bug
- SparkApplication依赖第三方jar文件解决方式
- MapReduce工作原理图文详解
- table表格:全选/全部选/批量删除
- 惠战双十二,FL Studio特价限量抢购