博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
调用各天气预报API (转载)
阅读量:7157 次
发布时间:2019-06-29

本文共 4893 字,大约阅读时间需要 16 分钟。

转自http://blog.csdn.net/l_ch_g/article/details/8205817  

豆瓣测试接口

新浪天气预报API

http://php.weather.sina.com.cn/xml.php?city=%B1%B1%BE%A9&password=DJOYnieT8234jlsK&day=0

其中,city后的城市转码。

Password固定

Day为0表示当天天气,1表示第二天的天气,2表示第三天的天气,以此类推,最大为4

返回的XML为

说明:

<Profiles> <Weather> <city>北京</city> <status1>晴</status1> <status2>晴</status2> <figure1>qing</figure1> <figure2>qing</figure2> <direction1>无持续风向</direction1> <direction2>无持续风向</direction2> <power1>≤3</power1> <power2>≤3</power2> <temperature1>7</temperature1> <temperature2>-5</temperature2> <ssd>0</ssd> <tgd1>7</tgd1> <tgd2>7</tgd2> <zwx>2</zwx> <ktk>7</ktk> <pollution>3</pollution> <xcz></xcz> <zho></zho> <diy></diy> <fas></fas> <chy>6</chy> <zho_shuoming>暂无</zho_shuoming> <diy_shuoming>暂无</diy_shuoming> <fas_shuoming>暂无</fas_shuoming> <chy_shuoming>棉衣、冬大衣、皮夹克、内着衬衫或羊毛内衣、毛衣、外罩大衣</chy_shuoming> <pollution_l>一般</pollution_l> <zwx_l>弱</zwx_l> <ssd_l>较凉</ssd_l> <fas_l>暂无</fas_l> <zho_l>暂无</zho_l> <chy_l>薄冬衣</chy_l> <ktk_l>建议开启(制热)</ktk_l> <xcz_l>暂无</xcz_l> <diy_l>暂无</diy_l> <pollution_s>对空气污染物扩散无明显影响</pollution_s> <zwx_s>紫外线弱</zwx_s> <ssd_s>老年、幼儿、体弱者外出需要带上薄围巾、薄手套。</ssd_s> <ktk_s>建议开启空调</ktk_s> <xcz_s>暂无</xcz_s> <gm>2</gm> <gm_l>易发期</gm_l> <gm_s>天气很凉,季节转换的气候,慎重增加衣服;较易引起感冒;</gm_s> <yd>5</yd> <yd_l>不适宜</yd_l> <yd_s>虽然晴空万里,但是户外运动时会感到很凉;</yd_s> <savedate_weather>2013-03-01</savedate_weather> <savedate_life>2013-03-01</savedate_life> <savedate_zhishu>2013-03-01</savedate_zhishu> </Weather> </Profiles>

标签中1表示白天,2表示夜间
<status> < figure> <direction> <power> <temperature> <ssd> <ssd_l> <ssd_s> <tgd> <zwx> <zwx_l> <zwx_s> <ktk> <ktk_l> <ktk_s> <pollution> <pollution_l> <pollution_s> <xcz> <xcz_l> <xcz_s> <chy> <chy_l> <chy_shuoming> <gm> <gm_l> <gm_s> <yd> <yd_l> <yd_s> <zho> <zho_l> <zho_shuoming> <diy> <diy_l> <diy_shuoming> <fas> <fas_l> <fas_shuoming> <savedate_weather> <savedate_life> <savedate_zhishu> 天气情况中文 天气情况拼音 风向 风级 温度 体感指数数值 体感度指数 体感度指数说明 体感温度 紫外线指数数值 紫外线指数 紫外线指数说明 空调指数数值 空调指数   空调指数说明 污染指数数值 污染物扩散条件 污染指数说明 洗车指数数值 洗车指数 洗车指数说明 穿衣指数数值 穿衣指数 穿衣说明 感冒指数数值 感冒指数 感冒指数说明 运动指数数值 运动指数 运动指数说明
天气预报日期 生活日期 指数日期

www.weather.com

CHXX0138 为武汉的天气代码

Unit=m 温度以摄氏度显示;去掉该参数,温度以华氏度显示

Dayf为0,1返回当天天气,其他数字为多天天气,最大可为5,返回当天及往后4天的天气预报

Par为注册时返回的Partner ID: 1220552427

Key为注册时返回的License Key: c168fcf83120f8ed

说明:

<loc id="CHXX0138"> <dnam>Wuhan, China</dnam> <tm>11:37 AM</tm> <lat>30.58</lat> <lon>114.27</lon> <sunr>6:49 AM</sunr> <suns>5:26 PM</suns> <zone>8</zone> </loc> 城市的天气代码 城市,国家 查询时间 纬度 经度 日出时间 日落时间
<cc></cc> 当前天气
<lsup>11/16/10 10:00 AM Local Time</lsup> <obst>Wuhan, CHINA</obst> <tmp>48</tmp> <flik>48</flik> <t>Fog</t> <icon>20</icon> 更新时间 当前温度 体感温度 天气情况 天气图标
<bar> <r>30.36</r> <d>steady</d> </bar>

<wind> <s>
2</s> <gust>
N/A</gust> <d>
0</d> <t>
VAR</t> </wind> 风速2英里/小时  

<dayf></dayf>    
传入的dayf参数,查询几天就有几个child <lsup>11/16/10 2:36 PM Local Time</lsup>  <day d="
0" t="
Tuesday" dt="
Nov 16"> <hi>N/A</hi> <low>43</low> <sunr>6:49 AM</sunr> <suns>5:26 PM</suns>  <part p="
d"> <icon>44</icon> <t>N/A</t>  <wind> <s>N/A</s> <gust>N/A</gust> <d>N/A</d> <t>N/A</t> </wind> <bt>N/A</bt> <ppcp>10</ppcp> <hmid>N/A</hmid> </part>  <part p="
n"> <icon>33</icon> <t>Mostly Clear</t>  <wind> <s>5</s> <gust>N/A</gust> <d>131</d> <t>SE</t> </wind> <bt>M Clear</bt> <ppcp>10</ppcp> <hmid>92</hmid> </part> </day> 更新时间 日期 高温 低温 日出时间 日落时间 白天天气情况 天气图标 风   风向 Chance of Precip:
10%    
夜间天气情况
天气图标
大部分地区晴朗无云
5英里/小时 东南风 风向:东南风 Chance of Precip:
10%

www.weather.com.cn

 数据页面

101200101 为武汉的城市代码

由  得到本机访问的IP,根据此IP查询到城市ID,

var ip="61.183.248.221";var id=101200101;if(typeof(id_callback)!="undefined"){id_callback();}

再根据城市ID返回该城市天气信息

该地址为天气插件的代码

各城市ID见 

yahoo天气预报

http://xml.weather.yahoo.com/forecastrss?w=2163866&u=c

w对应各个地方在yahoo数据库中的WOEID,如北京的WOEID是2151330;武汉为2163866;

u 为温度的单位,c表示摄氏度;f表示华氏度

http://xml.weather.yahoo.com/forecastrss?p=CHXX0138&u=c

p为城市天气代码,不推荐使用

没有预报几天的参数(或未找到),返回的XML中含有当天和第二天的天气基本情况。

说明:

<yweather:location city="Wuhan" region="" country="CH" /> <yweather:units temperature="C" distance="km" pressure="mb" speed="km/h" /> <yweather:wind chill="9" direction="0" speed="3.22" /> <yweather:atmosphere humidity="100" visibility="1.59" pressure="1015.92" rising="0" /> <yweather:astronomy sunrise="6:49 am" sunset="5:25 pm" /> 位置:城市,国家 单位:温度单位(摄氏),间距单位,气压单位,风速单位 风:冷风级别9,风向,风速3.22 大气情况:湿度,能见度,压强, 天文:日出6:49am,日落5:25pm
<title>Conditions for Wuhan, CH at 10:00 am CST</title> <geo:lat>30.58</geo:lat> <geo:long>114.27</geo:long> <link></link> <pubDate>Tue, 16 Nov 2010 10:00 am CST</pubDate> <yweather:condition text="Fog" code="20" temp="9" date="Tue, 16 Nov 2010 10:00 am CST" /> 纬度 经度 链接 更新时间/查询时间 天气情况:text天气情况(雾),code天气图标,temp温度9摄氏度,date日期
<yweather:forecast day="Tue" date="16 Nov 2010" low="6" high="16" text="Mostly Sunny" code="34" /> <yweather:forecast day="Wed" date="17 Nov 2010" low="8" high="19" text="Sunny" code="32" /> 天气预报:day星期,date日期,low低温,high高温,text天气情况,code天气图标

转载于:https://www.cnblogs.com/liuxingzi/archive/2013/06/06/3404353.html

你可能感兴趣的文章
日记:八月份的总结
查看>>
Liunx 特殊权限 suid sgid t
查看>>
Memcache的安装和使用【转】
查看>>
Android NDK OpenCV C++
查看>>
SQLAlchemy基础操作三
查看>>
(六)注解式控制器详解
查看>>
LeetCode OJ:Word Pattern(单词模式)
查看>>
[BJWC 2011]元素
查看>>
textbox获取焦点选中内容
查看>>
Map Wiki -- proposed by Shuo Ren
查看>>
字符函数 php
查看>>
js数组练习
查看>>
视图 Model转集合
查看>>
会计的思考(43):会计应在哪办公?
查看>>
c#自定义液晶数字控件
查看>>
Qt编写自定义控件11-设备防区按钮控件
查看>>
Qt编写安防视频监控系统(界面很漂亮)
查看>>
[POJ 1066]Treasure Hunt
查看>>
【CSON原创】HTML5游戏框架cnGameJS开发实录
查看>>
Linux配置防火墙8080端口
查看>>