中国天气weather.com
http://m.weather.com.cn/data/101110101.html(六天预报)
http://www.weather.com.cn/data/sk/101110101.html(实时天气信息)
其中101110101是城市的代码,获得城市代码进入<br />
由 http://61.4.185.48:81/g/ 得到本机访问的IP,根据此IP查询到城市ID,<br />
var ip=”61.183.248.221”;var id=101200101;if(typeof(id_callback)!=”undefined”){id_callback();}。<br />
C#代码
public string GetWeatherData()
{
string path = “ http://m.weather.com.cn/data/%22;
string[] citys = { “**”, “**”, “**”, “**”, “**” };// 城市编号 自己去找吧~
string html = “{"result":[”; //返回的数据<br />
foreach (string url in citys)
{
WebRequest req = WebRequest.Create(path + url + “.html”);
WebResponse res = req.GetResponse();
Stream receiveStream = res.GetResponseStream();
Encoding encode = Encoding.GetEncoding(“UTF-8”);
StreamReader sr = new StreamReader(receiveStream, encode);
string temp = sr.ReadToEnd();
temp = temp.Substring(0, temp.Length - 1);
temp += “},”;
html += temp;
}
html = html.Substring(0, html.Length - 1);
html += “]}”;
return html;
}
weatherinfo对象部分数据说明———
index_uv:紫外线指数<br />
index :穿衣指数
temp1 :温度
weather1:天气情况
fx1 :风向
fl1 :风力
date_y :日期
fchh :时间
中国天气网返回未来7天预报</b></span>
Java代码
- city "北京" //城市名称
- city_en "beijing"//应为名称
- date_y "2011年10月18日"//当前日期
- date "辛卯年"//阴历年
- week "星期二"//星期几
- fchh "18"//不详
- cityid "101010100"//城市编码
- //这里的温度 在下午更新后是这样的, 具体的更新点儿有待补上(下午好像是18点左右,白天的自己研究去吧 哈哈)
- //当那个更新点未到达之前是这样的:"temp1":"19℃~12℃", 也就是今天的最高温和最低温,也就是每天都会有个最高温和最低温,就看是那个点更新的数据了….
- temp1 "10℃~19℃"//当前日期是18日那这第一个的温度为19日凌晨到19日中午是的温度,下面以此类推
- temp2 "12℃~20℃"
- temp3 "11℃~21℃"
- temp4 "11℃~19℃"
- temp5 "13℃~18℃"
- temp6 "10℃~17℃"
- tempF1 "50℉~66.2℉"//华氏温度 同上
- tempF2 "53.6℉~68℉"
- tempF3 "51.8℉~69.8℉"
- tempF4 "51.8℉~66.2℉"
- tempF5 "55.4℉~64.4℉"
- tempF6 "50℉~62.6℉"
- weather1 "晴转阴"//同温度一样也是19日凌晨也可以说成是18日23:59:59秒//下面类推
- weather2 "阴转多云"
- weather3 "多云转晴"
- weather4 "晴转多云"
- weather5 "阴"
- weather6 "多云"
- img1 "0"//对应的显示图片编号
- img2 "2"
- img3 "2"
- img4 "1"
- img5 "1"
- img6 "0"
- img7 "0"
- img8 "1"
- img9 "2"
- img10 "99"//这个就不对了不知道为啥
- img11 "1"
- img12 "99"
- img_single "2"
- img_title1 "晴"//18日夜间
- img_title2 "阴"//19日白天
- img_title3 "阴"//19日夜间
- img_title4 "多云"//20日白天
- img_title5 "多云"//20日夜间 一次类推
- img_title6 "晴"
- img_title7 "晴"
- img_title8 "多云"
- img_title9 "阴"
- img_title10 "阴"
- img_title11 "多云"
- img_title12 "多云"
- img_title_single "阴"
- wind1 "微风"//一天的风力
- wind2 "微风"
- wind3 "微风"
- wind4 "微风"
- wind5 "微风"
- wind6 "微风"
- fx1 "微风"//这2个就不知道了有待研究
- fx2 "微风"
- fl1 "小于3级"//风力
- fl2 "小于3级"
- fl3 "小于3级"
- fl4 "小于3级"
- fl5 "小于3级"
- fl6 "小于3级"
- //这里的这些生活指数也是和上面的更新点有关系 18点左右更新的就是明天的生活指数了哈哈
- index "舒适"//舒适度指数
- index_d "建议着薄型套装或牛仔衫裤等春秋过渡装。年老体弱者宜着套装、夹克衫等。 //对应的描述
- index48 "暖"///这2个不清楚了
- index48_d "较凉爽,建议着长袖衬衫加单裤等春秋过渡装。年老体弱者宜着针织长袖衬衫、马甲和长裤。"
- index_uv "最弱"//紫外线指数
- index48_uv "弱"
- index_xc "适宜"//洗车指数
- index_tr "很适宜"//旅游指数
- index_co "舒适"//舒适度指数
- st1 "20"
- st2 "11"
- st3 "20"
- st4 "11"
- st5 "20"
- st6 "11"
- index_cl "较适宜"//晨练指数
- index_ls "不太适宜"//晾晒指数
- index_ag "不易发"// 息斯敏过敏气象指数
实时天气:</b></span>
Java代码
- city "北京"//城市
- cityid "101010100"//城市编码
- temp "17"//当前温度
- WD "东风"//风向
- WS "2级"//风力
- SD "70%"//相对湿度
- WSE "2"//风力
- time "14:20"//更新时间
- isRadar "1"//是否有雷达图
-
Radar "JC_RADAR_AZ9010_JB"//雷达图地址 http://www.weather.com.cn/html/radar/JC_RADAR_AZ9010_JB.shtml
中国天气网城市代码:
1. XML接口http://flash.weather.com.cn/wmaps/xml/china.xml这个是全国天气的根节点,列出所有的省,其中的pyName字段是各个省XML的文件名,比如北京的是beijing,那就意味着北京的XML地址为<a id="url_7" href="http://flash.weather.com.cn/wmaps/xml/beijing.xml" target="_blank">http://flash.weather.com.cn/wmaps/xml/beijing.xml</a>一个省的天气,其中列出该省各个市的数据,北京就列出各个区。tmp1是最低温低,tmp2是最高温度,url非常重要,我们一会儿再说。state1和state2是神马转神马,每个数代表一个天气现象。天气现象非常多,我本想全部分析出来,后来直接放弃了这个想法。因为我看到了一个城市的天气现象的编码是26...我现在知道的有0.晴 1.多云 2.阴6.雨夹雪 7.小雨 8.中雨 13.阵雪 14.小雪 其中后来发现知道这个没用,这个数字的主要作用是检索图片的!!!</span>
2. 图片接口http://m.weather.com.cn/img/c0.gif http://m.weather.com.cn/img/b0.gifhttp://www.weather.com.cn/m/i/weatherpic/29x20/d0.gifhttp://www.weather.com.cn/m2/i/icon_weather/29x20/n00.gif这个图就是天气现象0(晴)的图片,其他天气现象的图片依此类推。c打头的图片是20*20像素的,b打头的是50*46像素的,d打头的是反白的图标,29*20像素,n打头的是夜间反白图标,29*20像素,注意这里的文件名是两位数字! 也许还有更多的图标,等待大家发掘啦~
3. JSON接口真没想到~居然有JSON接口~JSON在iPhone上分析起来要比XML简单很多<a id="url_9" href="http://m.weather.com.cn/data/101010200.html" target="_blank">http://m.weather.com.cn/data/101010200.html</a>这个是北京的JSON数据,那个HTML的名字是根据上文XML中的url得到的。这个JSON中包含了实时数据、7天天气预报、气象指数等丰富的数据</span>
国家气象局提供的天气预报接口</b></span>
接口地址:</b></span>
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
对于第三个接口,返回信息比较全面,也是以json格式提供,格式如下</span>
{"weatherinfo": {
//基本信息;
"city":"北京","city_en":"beijing",
"date_y":"2012年2月16日", "date":"", "week":"星期四", "fchh":"11", "cityid":"101010100",
//摄氏温度
"temp1":"2℃~-7℃",
"temp2":"1℃~-7℃",
"temp3":"4℃~-7℃",
"temp4":"7℃~-5℃",
"temp5":"5℃~-3℃",
"temp6":"5℃~-2℃",
//华氏温度;
"tempF1":"35.6℉~19.4℉",
"tempF2":"33.8℉~19.4℉",
"tempF3":"39.2℉~19.4℉",
"tempF4":"44.6℉~23℉",
"tempF5":"41℉~26.6℉",
"tempF6":"41℉~28.4℉",
//天气描述;
"weather1":"晴",
"weather2":"晴",
"weather3":"晴",
"weather4":"晴转多云",
"weather5":"多云",
"weather6":"多云转阴",
//天气描述图片序号
"img1":"0",
"img2":"99",
"img3":"0",
"img4":"99",
"img5":"0",
"img6":"99",
"img7":"0",
"img8":"1",
"img9":"1",
"img10":"99",
"img11":"1",
"img12":"2",
"img_single":"0",
//图片名称;
"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":"晴",
//风速描述</span>
"wind1":"北风3-4级转微风",
"wind2":"微风",
"wind3":"微风",
"wind4":"微风",
"wind5":"微风",
"wind6":"微风",
//风速级别描述</span>
"fx1":"北风",
"fx2":"微风",
"fl1":"3-4级转小于3级",
"fl2":"小于3级",
"fl3":"小于3级",
"fl4":"小于3级",
"fl5":"小于3级",
"fl6":"小于3级",
//今天穿衣指数;
"index":"冷",
"index_d":"天气冷,建议着棉衣、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣或冬大衣。",
//48小时穿衣指数
"index48":"冷",
"index48_d":"天气冷,建议着棉衣、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣或冬大衣。",
//紫外线及48小时紫外线</span>
"index_uv":"弱",
"index48_uv":"弱",
//洗车
"index_xc":"适宜",
//旅游
"index_tr":"一般",
//舒适指数</span>
"index_co":"较不舒适",
"st1":"1",
"st2":"-8",
"st3":"2",
"st4":"-4",
"st5":"5",
"st6":"-5",
//晨练
"index_cl":"较不宜",
//晾晒
"index_ls":"基本适宜",
//过敏
"index_ag":"极不易发"}}
</p>