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
这三个已经停用,数据不再更新,即使修改Referer,得到的已经不是正确的信息。
官网提供的API
一、调用规范 规范用于指导三方合作伙伴合理调用指数、3天常规预报(24小时)预报服务数据。
请求方式:http get
接口组成:由固定URL加5个不同的参数组成,完整URL需客户端经过固定方式加密后使用。
数据返回:json
完整URL:http://open.weather.com.cn/data/?areaid=""&type=""&date=""&appid=""&key=".urlencode($key);
固定URL:http://open.weather.com.cn/data/
需要申请ID
返回数据:
{
"c": {
"c1": "101010100",
"c2": "beijing",
"c3": "北京",
"c4": "beijing",
"c5": "北京",
"c6": "beijing",
"c7": "北京",
"c8": "china",
"c9": "中国",
"c10": "1",
"c11": "010",
"c12": "100000",
"c13": 116.391000,
"c14": 39.904000,
"c15": "33",
"c16": "AZ9010",
"c17": "+8"
},
"f": {
"f1": [{
"fa": "",
"fb": "01",
"fc": "",
"fd": "13",
"fe": "",
"ff": "0",
"fg": "",
"fh": "0",
"fi": "05:17|19:05"
},
{
"fa": "01",
"fb": "00",
"fc": "28",
"fd": "15",
"fe": "0",
"ff": "0",
"fg": "0",
"fh": "0",
"fi": "05:16|19:06"
},
{
"fa": "00",
"fb": "01",
"fc": "31",
"fd": "15",
"fe": "0",
"ff": "0",
"fg": "0",
"fh": "0",
"fi": "05:15|19:07"
}],
"f0": "201604281800"
}
}
================================================================================
中华万年历API
抓包中华万年历得到的接口(JSON):
http://wthrcdn.etouch.cn/weather_mini?city=北京
通过城市名字获得天气数据,json数据
http://wthrcdn.etouch.cn/weather_mini?citykey=101010100
通过城市id获得天气数据,json数据
数据和中国天气网(www.weather.com.cn)一致
数据:
{
"desc": "OK",
"status": 1000,
"data": {
"wendu": "22",
"ganmao": "各项气象条件适宜,无明显降温过程,发生感冒机率较低。",
"forecast": [{
"fengxiang": "南风",
"fengli": "3-4级",
"high": "高温 26℃",
"type": "多云",
"low": "低温 13℃",
"date": "28日星期四"
},
{
"fengxiang": "无持续风向",
"fengli": "微风级",
"high": "高温 28℃",
"type": "多云",
"low": "低温 15℃",
"date": "29日星期五"
},
{
"fengxiang": "无持续风向",
"fengli": "微风级",
"high": "高温 31℃",
"type": "晴",
"low": "低温 15℃",
"date": "30日星期六"
},
{
"fengxiang": "无持续风向",
"fengli": "微风级",
"high": "高温 29℃",
"type": "多云",
"low": "低温 20℃",
"date": "1日星期天"
},
{
"fengxiang": "北风",
"fengli": "4-5级",
"high": "高温 26℃",
"type": "小到中雨",
"low": "低温 13℃",
"date": "2日星期一"
}],
"yesterday": {
"fl": "微风",
"fx": "无持续风向",
"high": "高温 19℃",
"type": "小雨",
"low": "低温 12℃",
"date": "27日星期三"
},
"aqi": "118",
"city": "北京"
}
}
XML
http://wthrcdn.etouch.cn/WeatherApi?citykey=101010100
通过城市id获得天气数据,xml文件数据,
当错误时会有<error>节点
http://wthrcdn.etouch.cn/WeatherApi?city=北京
通过城市名字获得天气数据,xml文件数据
数据:
<resp>
<city>北京</city>
<updatetime>18:45</updatetime>
<wendu>22</wendu>
<fengli>2级</fengli>
<shidu>33%</shidu>
<fengxiang>东南风</fengxiang>
<sunrise_1>05:19</sunrise_1>
<sunset_1>19:06</sunset_1>
<sunrise_2/>
<sunset_2/>
<environment>
<aqi>118</aqi>
<pm25>61</pm25>
<suggest>儿童、老年人及心脏、呼吸系统疾病患者人群应减少长时间或高强度户外锻炼</suggest>
<quality>轻度污染</quality>
<MajorPollutants>臭氧8小时</MajorPollutants>
<o3>185</o3>
<co>1</co>
<pm10>101</pm10>
<so2>4</so2>
<no2>24</no2>
<time>18:00:00</time>
</environment>
<yesterday>
<date_1>27日星期三</date_1>
<high_1>高温 19℃</high_1>
<low_1>低温 12℃</low_1>
<day_1>
<type_1>小雨</type_1>
<fx_1>无持续风向</fx_1>
<fl_1>微风</fl_1>
</day_1>
<night_1>
<type_1>阴</type_1>
<fx_1>无持续风向</fx_1>
<fl_1>微风</fl_1>
</night_1>
</yesterday>
<forecast>
<weather>
<date>28日星期四</date>
<high>高温 26℃</high>
<low>低温 13℃</low>
<day>
<type>多云</type>
<fengxiang>南风</fengxiang>
<fengli>3-4级</fengli>
</day>
<night>
<type>多云</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</night>
</weather>
<weather>
<date>29日星期五</date>
<high>高温 28℃</high>
<low>低温 15℃</low>
<day>
<type>多云</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</day>
<night>
<type>晴</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</night>
</weather>
<weather>
<date>30日星期六</date>
<high>高温 31℃</high>
<low>低温 15℃</low>
<day>
<type>晴</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</day>
<night>
<type>多云</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</night>
</weather>
<weather>
<date>1日星期天</date>
<high>高温 29℃</high>
<low>低温 20℃</low>
<day>
<type>多云</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</day>
<night>
<type>小雨</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</night>
</weather>
<weather>
<date>2日星期一</date>
<high>高温 26℃</high>
<low>低温 13℃</low>
<day>
<type>小到中雨</type>
<fengxiang>北风</fengxiang>
<fengli>4-5级</fengli>
</day>
<night>
<type>多云</type>
<fengxiang>北风</fengxiang>
<fengli>3-4级</fengli>
</night>
</weather>
</forecast>
<zhishus>
<zhishu>
<name>晨练指数</name>
<value>适宜</value>
<detail>天气不错,空气清新,是您晨练的大好时机,建议不同年龄段的人们积极参加户外健身活动。</detail>
</zhishu>
<zhishu>
<name>舒适度</name>
<value>较舒适</value>
<detail>白天天气晴好,您在这种天气条件下,会感觉早晚凉爽、舒适,午后偏热。</detail>
</zhishu>
<zhishu>
<name>穿衣指数</name>
<value>舒适</value>
<detail>建议着长袖T恤、衬衫加单裤等服装。年老体弱者宜着针织长袖衬衫、马甲和长裤。</detail>
</zhishu>
<zhishu>
<name>感冒指数</name>
<value>少发</value>
<detail>各项气象条件适宜,无明显降温过程,发生感冒机率较低。</detail>
</zhishu>
<zhishu>
<name>晾晒指数</name>
<value>适宜</value>
<detail>天气不错,适宜晾晒。赶紧把久未见阳光的衣物搬出来吸收一下太阳的味道吧!</detail>
</zhishu>
<zhishu>
<name>旅游指数</name>
<value>适宜</value>
<detail>天气较好,但丝毫不会影响您出行的心情。温度适宜又有微风相伴,适宜旅游。</detail>
</zhishu>
<zhishu>
<name>紫外线强度</name>
<value>中等</value>
<detail>属中等强度紫外线辐射天气,外出时建议涂擦SPF高于15、PA+的防晒护肤品,戴帽子、太阳镜。</detail>
</zhishu>
<zhishu>
<name>洗车指数</name>
<value>较适宜</value>
<detail>较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。</detail>
</zhishu>
<zhishu>
<name>运动指数</name>
<value>较适宜</value>
<detail>天气较好,户外运动请注意防晒,推荐您在室内进行低强度运动。</detail>
</zhishu>
<zhishu>
<name>约会指数</name>
<value>适宜</value>
<detail>天气较好,和恋人一起徜徉于熙攘人群中或漫步于柔软草地上,都是不错的主意哦。</detail>
</zhishu>
<zhishu>
<name>雨伞指数</name>
<value>不带伞</value>
<detail>天气较好,不会降水,因此您可放心出门,无须带雨伞。</detail>
</zhishu>
</zhishus>
</resp>
一周天气预报接口
http://mobile.weather.com.cn/data/forecast/101010100.html?_=1461845405
1461845405为Unix的时间戳,貌似该参数没有什么用处?
返回数据:
{
"c": {
"c1": "101010100",
"c2": "beijing",
"c3": "北京",
"c4": "beijing",
"c5": "北京",
"c6": "beijing",
"c7": "北京",
"c8": "china",
"c9": "中国",
"c10": "1",
"c11": "010",
"c12": "100000",
"c13": "116.391",
"c14": "39.904",
"c15": "33",
"c16": "AZ9010",
"c17": "+8"
},
"f": {
"f1": [{
"fa": "01",
"fb": "03",
"fc": "10",
"fd": "5",
"fe": "0",
"ff": "0",
"fg": "0",
"fh": "0",
"fi": "06:21|17:40"
},
{
"fa": "07",
"fb": "07",
"fc": "19",
"fd": "12",
"fe": "0",
"ff": "0",
"fg": "0",
"fh": "0",
"fi": "06:22|17:38"
},
{
"fa": "02",
"fb": "00",
"fc": "15",
"fd": "5",
"fe": "8",
"ff": "8",
"fg": "3",
"fh": "1",
"fi": "06:23|17:37"
},
{
"fa": "00",
"fb": "00",
"fc": "16",
"fd": "4",
"fe": "0",
"ff": "0",
"fg": "0",
"fh": "0",
"fi": "06:24|17:35"
},
{
"fa": "00",
"fb": "00",
"fc": "18",
"fd": "7",
"fe": "0",
"ff": "0",
"fg": "0",
"fh": "0",
"fi": "06:25|17:34"
},
{
"fa": "00",
"fb": "01",
"fc": "18",
"fd": "8",
"fe": "0",
"ff": "0",
"fg": "0",
"fh": "0",
"fi": "06:26|17:32"
},
{
"fa": "01",
"fb": "01",
"fc": "16",
"fd": "6",
"fe": "0",
"ff": "0",
"fg": "0",
"fh": "0",
"fi": "06:27|17:31"
}],
"f0": "201310121100"
}
}
日期始终是201310121100,原因是服务器限制了Referer
气象图标下载
http://openweather.weather.com.cn/Home/Help/icon/iid/10.html
获取全国所有城市代码列表
方法一
XML接口根节点: http://flash.weather.com.cn/wmaps/xml/china.xml
XML接口主要作用是递归获取全国几千个县以上单位的城市代码,如:
http://flash.weather.com.cn/wmaps/xml/liaocheng.xml
方法二
更新:最新发现可以一次性获取全国+国外主要城市,8763个城市列表信息。
URL:http://mobile.weather.com.cn/js/citylist.xml