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

推荐订阅源

Google DeepMind News
Google DeepMind News
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
N
News and Events Feed by Topic
GbyAI
GbyAI
I
InfoQ
P
Privacy & Cybersecurity Law Blog
AWS News Blog
AWS News Blog
Cisco Talos Blog
Cisco Talos Blog
C
Check Point Blog
Recent Announcements
Recent Announcements
D
Darknet – Hacking Tools, Hacker News & Cyber Security
D
Docker
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Scott Helme
Scott Helme
C
CERT Recently Published Vulnerability Notes
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
News and Events Feed by Topic
C
CXSECURITY Database RSS Feed - CXSecurity.com
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
W
WeLiveSecurity
S
Securelist
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
www.infosecurity-magazine.com
www.infosecurity-magazine.com
K
Kaspersky official blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Schneier on Security
Schneier on Security
Stack Overflow Blog
Stack Overflow Blog
S
Security Affairs
NISL@THU
NISL@THU
O
OpenAI News
Vercel News
Vercel News
C
Cyber Attacks, Cyber Crime and Cyber Security
Y
Y Combinator Blog
T
Tor Project blog
G
GRAHAM CLULEY
T
Tailwind CSS Blog
博客园 - Franky
Webroot Blog
Webroot Blog
Simon Willison's Weblog
Simon Willison's Weblog
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
V2EX - 技术
V2EX - 技术
H
Help Net Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
F
Full Disclosure

博客园 - 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()转换为数组,遍历数组去除数据即可。