`
yhz61010
  • 浏览: 551537 次
  • 来自: -
博客专栏
63c13ecc-ef01-31cf-984e-de461c7dfde8
libgdx 游戏开发
浏览量:11981
社区版块
存档分类
最新评论

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

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

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

  首先要解决的就是关于天气数据来源的问题。现在关于天气的 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 信息,就可以获取任何城市的天气信息了。
  大功告成!
2
5
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics