python 实现天气预报功能


中国国家气象局提供了获取所在城市天气预报信息的接口。通过这个接口,我们就可以获取天气信息了。

中国国家气象局天气预报接口总共提供了三个:



http://www.weather.com.cn/data/sk/101010100.html


http://www.weather.com.cn/data/cityinfo/101010100.html

http://m.weather.com.cn/data/101010100.html


其中,最详细的信息来自第三个接口。上面url中的101010100是城市代码,这里是北京的城市代码。只需要改变城市代码,就可以得到所在城市的天气信息。


如,武汉的城市代码是101200101,所以所需要的url应该为 http://m.weather.com.cn/data/101200101.html,从而就可以读到天气的信息。


天气信息的数据结构是json,数据如下:

{"weatherinfo":{"city":"武汉","city_en":"wuhan","date_y":"2012年7月2日","date":"","week":"星期一","fchh":"11","cityid":"101200101","temp1":"35℃~27℃","temp2":"34℃~27℃","temp3":"34℃~27℃","temp4":"35℃~27℃","temp5":"35℃~27℃","temp6":"35℃~28℃","tempF1":"95℉~80.6℉","tempF2":"93.2℉~80.6℉","tempF3":"93.2℉~80.6℉","tempF4":"95℉~80.6℉","tempF5":"95℉~80.6℉","tempF6":"95℉~82.4℉","weather1":"多云","weather2":"多云","weather3":"多云","weather4":"多云","weather5":"多云","weather6":"多云","img1":"1","img2":"99","img3":"1","img4":"99","img5":"1","img6":"99","img7":"1","img8":"99","img9":"1","img10":"99","img11":"1","img12":"99","img_single"

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值