惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
博客园_首页
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
雷峰网
雷峰网
D
Docker
博客园 - 司徒正美
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
U
Unit 42
J
Java Code Geeks
A
About on SuperTechFans
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security Affairs
I
Intezer
Cisco Talos Blog
Cisco Talos Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog RSS Feed
P
Privacy & Cybersecurity Law Blog
T
Tenable Blog
T
Threatpost
H
Hacker News: Front Page
G
Google Developers Blog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
L
Lohrmann on Cybersecurity
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
S
Secure Thoughts
GbyAI
GbyAI
NISL@THU
NISL@THU
S
Security @ Cisco Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Webroot Blog
Webroot Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - Warrior Sun

【再学WPF】模板 【再学WPF】自定义样式 Tomcat修改service.xml性能调优 增加最大并发连接数 网站并发量的计算方法 计算并发用户数的五种方法 用户中心 - 博客园 你怎么看《周鸿祎自述:我的互联网方法论》这本书? 如何让SQLServer的 itemNum 字段 按照数字大小顺序排序 中文网页的字体 怎么用钓鱼小药 [转]红帽 Red Hat Linux相关产品iso镜像下载【百度云】 IIS7.0上传文件限制的解决方法 特殊符号 如何得到天气情况?在那个接口获取? Windows Update 时出现8024402C的错误 OC中copy的使用 Access自动编号的初始值设置及重置编号 在Excel中将数字转换为大写 [SharpZipLib 未能加载文件或程序集] 解决方法
开源免费的天气预报接口API以及全国所有地区代码(国家气象局提供)
Warrior Sun · 2015-10-25 · via 博客园 - Warrior Sun

天气预报一直是各大网站的一个基本功能,最近小编也想在网站上弄一个,得瑟一下,在网络搜索了很久,终于找到了开源免费的天气预报接口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()转换为数组,遍历数组去除数据即可。