[原创] 关于 “中国天气网 - www.weather.com.cn” 相关的 API 总结

Waittingforyou 2013-05-09

现在关于天气预报的手机应用是非常的多,包括那些非常著名的应用(我就不指名了,大家应该都用过),我就纳了闷了,一个预报天气的应用把天气好好的预报了就得了呗,非得加那么多没有用的功能,弄得应用本身越来越臃肿,而且速度越来越慢,你们到底要干什么吗?

于是准备自己做一个专注天气预报的应用程序。

首先要解决的就是关于天气数据来源的问题。现在关于天气的API很多,不过,得到的数据要么是太少,要么就是不完全。于是我就准备自己从权威网站上抓取数据,从而获得天气信息。

于是乎,我就选取了从“中国天气网-www.weather.com.cn”获取数据。也许天气数据可能关乎国家安全(网上有人是这么说的啊~~~嘿嘿!),所以权威网站一般都不直接提供天气的API,于是我就自己分析了一下该网站的,得到了如下一些API,有了这些API,我就可以取得任何城市的天气信息了。

API如下:

1.获取中图首都,直辖市,自治区,省会信息(provid):

http://www.weather.com.cn/data/city3jdata/china.html

2.获取市,地区信息(districtid):

http://www.weather.com.cn/data/city3jdata/provshi/[provid].html

例如:

http://www.weather.com.cn/data/city3jdata/provshi/10107.html

3.获取区信息(cityid):

若provid为"10101北京","10102上海","10103天津","10104重庆",则获取区的API为

http://www.weather.com.cn/data/city3jdata/station/[provid]00.html

例如:

http://www.weather.com.cn/data/city3jdata/station/1010100.html

其它情况,API为

http://www.weather.com.cn/data/city3jdata/station/[provid][districtid].html

例如:

http://www.weather.com.cn/data/city3jdata/station/1010702.html

4.获取天气信息:

若provid为"10101北京","10102上海","10103天津","10104重庆",则获取天气的API为

http://www.weather.com.cn/weather/[provid][cityid]00.shtml

例如:

http://www.weather.com.cn/weather/101010200.shtml

其它情况,API为

http://www.weather.com.cn/weather/[provid][districtid][cityid].shtml

例如:

http://www.weather.com.cn/weather/101070201.shtml

根据以上API结合GPS信息,就可以获取任何城市的天气信息了。

大功告成!

相关推荐

kktode / 0评论 2013-09-09
pipimob / 0评论 2011-10-18