天气预报一直是各大网站的一个基本功能,最近小编也想在网站上弄一个,得瑟一下,在网络搜索了很久,终于找到了开源免费的天气预报接口API以及全国所有地区代码(国家气象局提供),具体如下:

国家气象局提供的天气预报接口

  • 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

城市的编号

其中101010100表示每个城市的编号,编号代码获取获取地址

  • 获取省级代码:http://www.weather.com.cn/data/list3/city.xml?level=1
  • 获取城市代码(比如安徽是22):http://www.weather.com.cn/data/list3/city22.xml?level=2
  • 获取区域代码(比如安庆是2206):http://www.weather.com.cn/data/list3/city2206.xml?level=3
    获取到安徽省安庆市望江县的代码是220607
  • 然后去加上中国代码请求URL:http://m.weather.com.cn/data/101220607.html 就可以获取当地天气。

图片接口

用过上面的api返回的数据中包含有图片名字可以通过一下地址访问

  • http://m.weather.com.cn/img/c0.gif
  • http://m.weather.com.cn/img/b0.gif
  • http://www.weather.com.cn/m/i/weatherpic/29×20/d0.gif
  • http: //www.weather.com.cn/m2/i/icon_weather/29×20/n00.gif

这个图就是天气现象0(晴)的 图片,其他天气现象的图片依此类推。c打头的图片是20*20像素的,b打头的是50*46像素的,d打头的是反白的图标,29*20像素,n打头的是夜 间反白图标,29*20像素,注意这里的文件名是两位数字!

解析数据

国家气象局提供的天气预报接口返回的是json数据,如果是php可以使用json_decode()转换为数组,遍历数组去除数据即可。

开源免费的天气预报接口API以及全国所有地区代码(国家气象局提供)的更多相关文章

  1. 开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供) 【转】

    国家气象局提供的天气预报接口 接口地址: http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn/data ...

  2. 开源免费天气预报接口API以及全国全部地区代码!!(国家气象局提供)

    国家气象局提供的天气预报接口 接口地址: http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn/data ...

  3. 开源免费天气预报接口API以及全国所有地区代码[值得收藏]

    国家气象局提供的天气预报接口 接口地址: http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn/data ...

  4. (转)免费天气预报接口API以及全国所有地区代码!!

    国家气象局提供的天气预报接口 接口地址: http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn/data ...

  5. 中国天气网-天气预报接口api

    中国天气网地址:http://www.weather.com.cn 请求服务 : 查询实时天气信息 http://www.weather.com.cn/data/sk/101110101.html 在 ...

  6. 天气预报接口api(中国天气网)

    中国天气weather.comhttp://m.weather.com.cn/data/101110101.html(六天预报) http://www.weather.com.cn/data/sk/1 ...

  7. ios 开源免费接口

    ios 开源免费接口 国家气象局提供的天气预报接口 接口地址: http://www.weather.com.cn/data/sk/101010100.html http://www.weather. ...

  8. 基于JAVA的全国天气预报接口调用示例

    step1:选择本文所示例的接口"全国天气预报接口" url:https://www.juhe.cn/docs/api/id/39/aid/87step2:每个接口都需要传入一个参 ...

  9. [Android] 免费天气预报接口

    [Android] 免费天气预报接口 这是 国家气象局提供的天气预报接口 [免费] 当然,网上有很多的收费API或者每天定次数的接口 使用 国家气象局 的步骤如下: 1.首先获取城市ID号 北京:10 ...

随机推荐

  1. 调用外部js文件测试

    test <p><img id="img" onclick="javascript:var s=document.createElement('scri ...

  2. 实现TCP、UDP相互通信及应用

    实验名称  Socket编程综合实验(1) 一.实验目的: 1.理解进程通信的原理及通信过程 2.掌握基于TCP和UDP的工作原理 3.掌握基本的Socket网络编程原理及方法 二.实验内容 1.掌握 ...

  3. 通过gradle来导入jar包

    1.通过gradle配置第三方jar包 我们看到,每个module都有一个build.gradle文件,它其实是对应module的配置文件.关于build.gradle文件中具体内容的含义,我们将在最 ...

  4. iOS开发之直接使用UISearchBar

    iOS开发中经常需要使用SearchBar,我们可以选择使用UISearchBar+UISearchController或者UISearchBar+UISearchDisplayController( ...

  5. Javascript词法分析

    词法分析的过程: 先分析参数 分析变量声明 分析函数声明 具体步骤: 在函数运行前的一瞬间,先生成Active Object活动对象; 函数声明的参数,形成AO的属性,值为undefined 接收参数 ...

  6. Mongodb优化

    本文将从各个层面讲述Mongodb的优化方法

  7. echo '<script>alert("插入成功")</script>';

    echo '<script>alert("插入成功")</script>'; <?php if ( ! defined('BASEPATH')) ex ...

  8. pyqt4:线程的串联运行方式

    有些时候我们在pyqt中需要线程串行运行,而不是并发运行,用以下方式,这是在网上找的,暂存. > Hello > I have something like the foll scenar ...

  9. Java & Android Color-Background

    int i = Color.parseColor("#FFFFFF"); int j = Color.rgb(255,255,255); 1.SetBackground(Drawa ...

  10. 简单的 JSON 对象进行深拷贝最简单的方法

    var json = { a: 123, b: '456' }; var json2 = JSON.parse(JSON.stringify(json)); 只需要先使用 JSON.stringify ...