天气预报接口

中国天气网(weather.com

【该接口如果用js直接调用会出现跨域问题,可以以自己的服务器作为跳板,js请求自己的服务器,自己的服务器(例如:PHP)再去请求该接口】

  • http://m.weather.com.cn/data/101110101.html(六天预报)
  • http://www.weather.com.cn/data/sk/101110101.html(实时天气信息)
  • http://m.weather.com.cn/data5/city.xml(获得第一级城市代码【省级】)
其中 101110101是城市的代码,那么我们如何得到城市的代码呢?
首先调用http://m.weather.com.cn/data5/city.xml得到XML如下:
<parsererror>
<sourcetext>01| 北京,02|上海,03|天津,04|重庆,05|黑龙江,06|吉林,07|辽宁,08|内蒙古,09|河北,10|山西,11|陕西,12|山东,13|新疆,14|西藏,15|青海,16|甘肃,17|宁夏,18|河南,19|江苏,20|湖北,21|浙江,22|安徽,23|福建,24|江西,25|湖南,26|贵州,27|四川,28|广东,29|云南,30|广西,31|海南,32|香港,33|澳门,34|台湾
</sourcetext></parsererror>
这部分是全国省份的List
现在例如我们要得到江苏的城市的list则调用
http://m.weather.com.cn/data5/city19.xml(在city后加入省份的ID)得到XML如下:

<parsererror>
<sourcetext>1901|南京,1902|无锡,1903|镇江,1904|苏州,1905|南通,1906|扬州,1907|盐城,1908|徐州,1909|淮安,1910|连云港,1911|常州,1912|泰州,1913|宿迁 </sourcetext>
</parsererror>

然后我想得到常州市底下的区县则调用
http://m.weather.com.cn/data5/ city1911.xml(在city后加入市级的ID)得到XML如下:
<parsererror>
<sourcetext>191101|常州,191102|溧阳,191103|金坛,191104|武进 ^</sourcetext>
</parsererror>

然后我想得到金坛底下的地方名则调用
http://m.weather.com.cn/data5/ city191103.xml(在city后加入市级的ID)得到XML如下:
<parsererror>
<sourcetext>191103|101191103</sourcetext>
</parsererror>
出现这种情况则说明你的地名已经到最后一级了此事你得到的 101191103则是城市的代码
此时你就可以用
  • http://m.weather.com.cn/data/101191103.html(六天预报)
  • http://www.weather.com.cn/data/sk/101191103.html(实时天气信息)

http://m.weather.com.cn/data/101191103.html(六天预报)得到的结果如下:

  1. ①weather1至weather6 是六天的天气(包含当天)
  2. ②temp1至temp6是六天的温度范围
  3. ③image_title1至image_title12是六天的天气(分为白天和晚上 image_title1是今天白天 , image_title1是今天晚上 ,image_title3是明天白天,依次类推)
  4. ④img1至img12 是六天的天气所对应的图标(分为白天和晚上,和 image_title 是对应的,例如:img1的值是7 ,则图标对应的urlhttp://m.weather.com.cn/weather_img/7.gif】)
{
    "weatherinfo": {
        "city": "金坛",
        "city_en": "jintan",
        "date_y": "2011年10月21日",
        "date": "辛卯年",
        "week": "星期五",
        "fchh": "08",
        "cityid": "101191103",
        "temp1": "23℃~16℃",
        "temp2": "24℃~16℃",
        "temp3": "22℃~12℃",
        "temp4": "18℃~9℃",
        "temp5": "19℃~11℃",
        "temp6": "22℃~13℃",
        "tempF1": "73.4℉~60.8℉",
        "tempF2": "75.2℉~60.8℉",
        "tempF3": "71.6℉~53.6℉",
        "tempF4": "64.4℉~48.2℉",
        "tempF5": "66.2℉~51.8℉",
        "tempF6": "71.6℉~55.4℉",
        "weather1": "小雨转阴",
        "weather2": "多云转晴",
        "weather3": "多云转小雨",
        "weather4": "小雨转阴",
        "weather5": "多云转晴",
        "weather6": "多云转阴",
        "img1": "7",
        "img2": "2",
        "img3": "1",
        "img4": "0",
        "img5": "1",
        "img6": "7",
        "img7": "7",
        "img8": "2",
        "img9": "1",
        "img10": "0",
        "img11": "1",
        "img12": "2",
        "img_single": "7",
        "img_title1": "小雨",
        "img_title2": "阴",
        "img_title3": "多云",
        "img_title4": "晴",
        "img_title5": "多云",
        "img_title6": "小雨",
        "img_title7": "小雨",
        "img_title8": "阴",
        "img_title9": "多云",
        "img_title10": "晴",
        "img_title11": "多云",
        "img_title12": "阴",
        "img_title_single": "小雨",
        "wind1": "南风3-4级",
        "wind2": "南风3-4级",
        "wind3": "东南风转东北风3-4级",
        "wind4": "北风4-5级",
        "wind5": "西北风转西风3-4级",
        "wind6": "南风转东风3-4级",
        "fx1": "南风",
        "fx2": "南风",
        "fl1": "3-4级",
        "fl2": "3-4级",
        "fl3": "3-4级",
        "fl4": "4-5级",
        "fl5": "3-4级",
        "fl6": "3-4级",
        "index": "暖",
        "index_d": "较凉爽,建议着长袖衬衫加单裤等春秋过渡装。年老体弱者宜着针织长袖衬衫、马甲和长裤。",
        "index48": "热",
        "index48_d": "天气较热,建议着短裙、短裤、短套装、T恤等夏季服装。年老体弱者宜着长袖衬衫和单裤。",
        "index_uv": "最弱",
        "index48_uv": "弱",
        "index_xc": "不宜",
        "index_tr": "适宜",
        "index_co": "舒适",
        "st1": "20",
        "st2": "13",
        "st3": "23",
        "st4": "15",
        "st5": "21",
        "st6": "7",
        "index_cl": "较不宜",
        "index_ls": "不宜",
        "index_ag": "易发"
    }
}


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值