lovablebox

学点东西...

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
偶然在博客园 看到一篇关于如何得到网易天气预报的帖子 有点启发 我自己也做了一个  
首先我们必须获得和城市相对应的代码,我在网易的网页中找到的城市编号换到中央气象台的也能用 
貌似都是通用的.....
查看http://news.163.com/weather/ 这个网页的源代码,只需要今日天气的部分和一些脚本语句。
具体效果如下 2种天气预报 呵呵 不知道哪个准一点``保存的位图``看着有点烂`` 


具体代码如下:
代码太多了 ``贴了就卡了 一段一段的贴把
首先是脚本
 1<script type="text/javascript">
 2function selectSubmit(){
 3var sfw = document.all.sfweather1_1.value;
 4cookit(sfw);
 5}

 6
 7function cookit() {
 8exDate = new Date
 9exDate.setMonth(exDate.getMonth()+9)
10if( confirm('您需要定制"'+cookit.arguments[0]+'"天气信息吗?'))
11{
12    var fcityid=s_cityid(cookit.arguments[0]);
13    if(fcityid!=false){
14    
15    //http://news.163.com/weather/news/qx1/59554.html
16     var addr1="http://travel.163.com/weather/new/"+escape(fcityid)+".html";
17     document.all("iframe2").src = addr1;
18   
19     var addr="http://www.weathercn.com/forecast/24time.jsp?sta_id="+escape(fcityid);
20     document.all("iframe1").src = addr;
21     document.all("label1").innerHTML = document.all("sfweather1").value + document.all("sfweather1_1").value;
22    // window.location.href = addr;
23   }
else{
24alert("这个城市暂时不能定制!");
25   }

26}

27}

28 
29 
30//根据选择的城市返回城市的编号
31function s_cityid(key)
32{
33    var labels=new Array("大连","青岛","宁波","厦门","汕头","深圳","敦煌","黄山","庐山","大同","威海","五台山","承德","泰山","峨眉山","大理","华山","桂林","北海","三亚","烟台","洛阳","潍坊","九华山","宜昌","张家界","开封","黄果树","九寨沟","丹东","淄博","秦皇岛","苏州","无锡","亚布力","景德镇","北海","珠海","连云港","延安","赣州","西沙","南沙岛","鞍山","绵阳","湛江","惠阳","伊宁","锦州","保定","佛山","扬州","常州","乐清","温州","武夷山市","开封","大庸","龙华","鄞县","北戴河","牙克石","满洲里","长白","大兴安岭","黑河","乌镇","普沱山","井冈山","鄱阳湖景区","张家界","衡山","迪庆","丽江","西双版纳","德钦","刚察","林芝","吐鲁番","伊犁","东京","京都","汉城","温哥华","渥太华","多伦多","波士顿","纽约","旧金山","洛杉矶","拉斯维加斯","迈阿密","芝加哥","圣保罗","惠灵顿","悉尼","墨尔本","惠灵顿","新加坡","河内","曼谷","文莱","雅加达","仰光","新德里","孟买","卡拉奇","吉隆坡","开普敦","开罗","法兰克福","维也纳","罗马","米兰","雅典","巴黎","罗马","巴塞罗那","伦敦","莫斯科","北京","天津","石家庄","太原","呼和浩特","沈阳","长春","哈尔滨","上海","杭州","合肥","福州","济南","郑州","武汉","长沙","广州","南宁","海口","成都","重庆","贵阳","昆明","拉萨","西安","兰州","西宁","银川","乌鲁木齐","台北","南京","南昌","香港","澳门","唐山","张家口","廊坊","邯郸","邢台","沧州","衡水","阳泉","晋城","晋中","临汾","运城","长治","朔州","忻州","包头","赤峰","海拉尔","锡林浩特","乌海","鄂尔多斯","葫芦岛","旅顺","本溪","朝阳","抚顺","铁岭","辽阳","营口","阜新","延边","吉林","白山","白城","四平","松原","辽源","牡丹江","齐齐哈尔","大庆","伊春","双鸭山","鹤岗","鸡西","佳木斯","七台河","绥化","黑河","昆山","南通","太仓","徐州","宜兴","镇江","淮安","常熟","盐城","泰州","湖州","金华","宁波","丽水","绍兴","雁荡山","衢州","嘉兴","台州","舟山","巢湖","蚌埠","安庆","六安","滁州","马鞍山","阜阳","宣城","铜陵","淮北","芜湖","亳州","宿州","淮南","龙岩","南平","宁德","莆田","泉州","三明","漳州","井冈山","萍乡","九江","上饶","抚州","吉安","鹰潭","宜春","枣庄","聊城","曲阜","济宁","临沂","菏泽","泰安","日照","东营","济源","开封","安阳","焦作","鹤壁","平顶山","商丘","濮阳","南阳","许昌","信阳","三门峡","驻马店","周口","新乡","黄冈","恩施","荆州","神农架","十堰","咸宁","襄樊","孝感","随州","黄石","荆门","鄂州","邵阳","常德","郴州","吉首","株洲","娄底","湘潭","益阳","永州","岳阳","株洲","衡阳","怀化","韶山","潮州","肇庆","汕尾","河源","韶关","揭阳","梅州","中山","惠州","东莞","清远","江门","茂名","德庆","阳江","百色","柳州","梧州","玉林","桂平","贺州","钦州","贵港","防城港","儋州","琼山","通什","文昌","泸州","内江","凉山","阿坝","巴中","广元","乐山","绵阳","德阳","攀枝花","雅安","宜宾","自贡","甘孜州","达州","安顺","赤水","遵义","铜仁","六盘水","毕节","凯里","都匀","保山","楚雄","德宏","红河","临沧","怒江","曲靖","思茅","文山","玉溪","临沧","昭通","昌都","阿里","那曲","日喀则","山南","韩城","安康","汉中","宝鸡","咸阳","榆林","渭南","商洛","铜川","白银","庆阳","嘉峪关","酒泉","天水","武威","张掖","甘南","临夏","平凉","定西","金昌","海北","海南","海西","黄南","果洛","西宁","玉树","固原","中卫","阿勒泰","阿克苏","昌吉","哈密","和田","喀什","克拉玛依","石河子","塔城","库尔勒","高雄");
34    var values=new Array("54662","54857","58562","59134","59316","59493","52418","58437","58506","53487","54774","53588","54423","54826","56385","56751","57046","57957","59644","59948","54765","57073","54843","58423","57461","57558","57091","57809","56182","54497","54830","54449","58357","58354","54094","58527","59644","59488","58044","53845","57993","59981","59997","54339","56196","59658","59298","51431","54337","54602","59288","58245","58343","58656","58659","58730","57091","57558","58367","58562","54449","50526","50514","54386","50442","50468","58456","58477","57894","58517","57558","57777","56543","56651","56959","56444","52754","56312","51573","51431","47662","47759","47108","71892","71628","71624","72509","72503","72494","72295","72386","72202","72530","83780","93436","94767","94866","93436","48698","48820","48455","96315","96749","40984","42182","43002","41780","48647","68816","62366","10637","11035","16242","16066","16716","07149","16242","08181","03772","27612","54511","54527","53698","53772","53463","54342","54161","50953","58367","58457","58321","58847","54823","57083","57494","57679","59287","59431","59758","56294","57516","57816","56778","55591","57036","52889","52866","53614","51463","58968","58238","58606","45005","45011","54534","54401","54515","53892","53798","54616","54702","53782","53976","53776","53868","53959","53882","53578","53674","53446","54218","50527","54102","53512","3543","54453","54660","54346","54324","54351","54249","54347","54471","54237","54292","54172","54371","50936","54157","50946","54260","54094","50745","50854","50774","50884","50775","50978","50873","50973","50853","50468","58356","58259","58377","58349","58027","58346","58248","58145","58352","58151",
35    "58450","58549","58562","58646","58453","58656","58633","58452","58660","58477","58326","58221","58424","58311","58236","58336","58203","58433","58429","58116","58334","58102","58122","58224","58927","58834","58846","58946","59131","58828","59126","57894","57786","58502","58623","58617","57797","8627","57793","58024","54806","54918","54915","54938","54906","54827","54945",
36    "54736","53978","57091","53898","53982","53990","57171","58005","54900","57178","57089","57297","57051","57290","57195","53986","57498","57447","57476","57362","57256","57590","57278","57482","57381","58407","57377","57496","57766","57662","57972","57649","57780","57763","57773","57674","57866","57584","57780","57872","57749","57771","59312","59278","59501","59293","59082","59315","59117","59485","59298","59289","59280","59476","59659","59269","59663","59211","59046","59265","59453","59254","59065","59632","59249","59635","59845","59757","59941","59856","57508","57503","56571","56172","57313","57206","56386","56196","56198","56666","56287","56492","56396","56146","57328","57806","57609","57713","57741","56693","57707","57825","57827","56748","56768","56844","56985","56951","56643","56783","56964","56994","56875","56951","56586","56137","55228","55299","55578","55598","53955","57245","57127","57016","57048","53646","57045","57143","53947","52896","53829","52533","52533","57006","52679","52652","56080","52984","53915","52995","52675","52853","52856","52737","52974","56043","52866","56029","53817","53704","51076","51628","51368","52203","51828","51709","51243","51356","51133","51656","59554");
37    for(var i=0;i<labels.length;i++)
38    {
39        if(labels[i]==key) return values[i] ;
40    }

41    return false
42}

43

还是脚本``
  1</script>
  2<script language="javascript">
  3    function sfsetcity1() 
  4    switch (document.all.sfweather1.value) 
  5    {
  6        case '':
  7        var labels=new Array("请选择城市");
  8        var values=new Array("");
  9        break;
 10        case '独立直辖市'
 11        var labels=new Array("请选择城市","北京","上海","天津","重庆"); 
 12        var values=new Array("","54511","11860","11861"); 
 13        break;
 14        case '特别行政区':
 15        var labels=new Array("请选择城市","香港","澳门");
 16        var values=new Array("","");
 17        break;
 18        case '台湾':
 19        var labels=new Array("请选择城市","台北","高雄");
 20        var values=new Array("","");
 21        break;
 22        case '广东省':
 23        var labels=new Array("请选择城市","广州","深圳","潮州","韶关","湛江","惠阳","清远","东莞","江门","茂名","肇庆","汕头","汕尾","河源","揭阳","梅州","中山","惠州","德庆","阳江","百色");
 24        var values=new Array("","");
 25        break;
 26        case '西藏':
 27        var labels=new Array("请选择城市","拉萨","阿里","昌都","那曲","日喀则","山南");
 28        var values=new Array("","");
 29        break;
 30        case '陕西省':
 31        var labels=new Array("请选择城市","西安","韩城","安康","汉中","宝鸡","咸阳","榆林","渭南","商洛","铜川");
 32        var values=new Array("","");
 33        break;
 34        case '甘肃省':
 35        var labels=new Array("请选择城市","兰州","白银","庆阳","酒泉","天水","武威","张掖","甘南","临夏","平凉","定西","金昌");
 36        var values=new Array("","");
 37        break;
 38        case '青海省':
 39        var labels=new Array("请选择城市","西宁","海北","海西","黄南","果洛","玉树","固原","中卫");
 40        var values=new Array("","");
 41        break;
 42        case '宁夏省':
 43        var labels=new Array("请选择城市","银川");
 44        var values=new Array("","");
 45        break;
 46        case '新疆':
 47        var labels=new Array("请选择城市","乌鲁木齐","阿勒泰","阿克苏","昌吉","哈密","和田","喀什","克拉玛依","石河子","塔城","库尔勒");
 48        var values=new Array("","");
 49        break;
 50        case '江苏省':
 51        var labels=new Array("请选择城市","苏州","南京","昆山","南通","太仓","徐州","宜兴","镇江","淮安","常熟","盐城","泰州");
 52        var values=new Array("","");
 53        break;
 54        case '云南省':
 55        var labels=new Array("请选择城市","保山","楚雄","德宏","红河","临沧","怒江","曲靖","思茅","文山","玉溪","昭通");
 56        var values=new Array("","");
 57        break;
 58        case '福建省':
 59        var labels=new Array("请选择城市","厦门","福州","龙岩","南平","宁德","莆田","泉州","三明","漳州");
 60        var values=new Array("","");
 61        break;
 62        case '海南省':
 63        var labels=new Array("请选择城市","三亚","海口","儋州","琼山","通什","文昌");
 64        var values=new Array("","");
 65        break;
 66        case '广西省':
 67        var labels=new Array("请选择城市","桂林","阳朔","南宁","柳州","梧州","玉林","桂平","贺州","钦州","贵港","防城港");
 68        var values=new Array("","");
 69        break;
 70        case '湖南省':
 71        var labels=new Array("请选择城市","长沙","邵阳","常德","郴州","吉首","株洲","娄底","湘潭","益阳","永州","岳阳","衡阳","怀化","韶山");
 72        var values=new Array("","");
 73        break;
 74        case '湖北省':
 75        var labels=new Array("请选择城市","武汉","宜昌","黄冈","恩施","荆州","神农架","十堰","咸宁","襄樊","孝感","随州","黄石","荆门","鄂州");
 76        var values=new Array("","");
 77        break;
 78        case '四川省':
 79        var labels=new Array("请选择城市","成都","泸州","内江","凉山","阿坝","巴中","广元","乐山","绵阳","德阳","攀枝花","雅安","宜宾","自贡","甘孜州","达州");
 80        var values=new Array("","");
 81        break;
 82        case '吉林省':
 83        var labels=new Array("请选择城市","长春","延边","吉林","白山","白城","四平","松原","辽源");
 84        var values=new Array("","");
 85        break;
 86        case '黑龙江':
 87        var labels=new Array("请选择城市","哈尔滨","齐齐哈尔","牡丹江","大庆","伊春","双鸭山","鹤岗","鸡西","佳木斯","七台河","黑河","绥化");
 88        var values=new Array("","");
 89        break;
 90        case '山东省':
 91        var labels=new Array("请选择城市","曲阜","临沂","烟台","济南","枣庄","聊城","济宁","菏泽","泰安","日照","东营");
 92        var values=new Array("","");
 93        break;
 94        case '山西省':
 95        var labels=new Array("请选择城市","大同","太原","阳泉","晋城","晋中","临汾","运城","长治","朔州","忻州");
 96        var values=new Array("","");
 97        break;
 98        case '内蒙古':
 99        var labels=new Array("请选择城市","呼和浩特","呼伦贝尔","锡林郭勒","包头","赤峰","海拉尔","乌海","鄂尔多斯","锡林浩特");
100        var values=new Array("","");
101        break;
102        case '辽宁省':
103        var labels=new Array("请选择城市","沈阳","大连","葫芦岛","旅顺","本溪","抚顺","铁岭","辽阳","营口","阜新");
104        var values=new Array("","");
105        break;
106        case '浙江省':
107        var labels=new Array("请选择城市","杭州","湖州","金华","宁波","丽水","绍兴","雁荡山","衢州","嘉兴","台州","舟山");
108        var values=new Array("","");
109        break;
110        case '安徽省':
111        var labels=new Array("请选择城市","合肥","巢湖","蚌埠","安庆","六安","滁州","马鞍山","阜阳","宣城","铜陵","淮北","芜湖","亳州","宿州","淮南");
112        var values=new Array("","");
113        break;
114        case '河南省':
115        var labels=new Array("请选择城市","郑州","济源","开封","安阳","焦作","鹤壁","平顶山","商丘","濮阳","南阳","许昌","信阳","三门峡","驻马店","周口","新乡");
116        var values=new Array("","");
117        break;
118        case '贵州省':
119        var labels=new Array("请选择城市","贵阳","安顺","赤水","遵义","铜仁","六盘水","毕节","凯里","都匀");
120        var values=new Array("","");
121        break;
122        case '江西省':
123        var labels=new Array("请选择城市","南昌","萍乡","九江","上饶","抚州","吉安","鹰潭","宜春");
124        var values=new Array("","");
125        break;
126        case '河北省':
127        var labels=new Array("请选择城市","石家庄","唐山","张家口","廊坊","邢台","邯郸","沧州","衡水");
128        var values=new Array("","");
129        break;
130        
131    }
 
132    document.all.sfweather1_1.options.length = 0;
133    for(var i = 0; i < labels.length; i++)
134    
135        document.all.sfweather1_1.add(document.createElement("OPTION"));
136        document.all.sfweather1_1.options[i].text=labels[i]; 
137        document.all.sfweather1_1.options[i].value=labels[i]; 
138    }
 
139    document.all.sfweather1_1.selectedIndex = 0
140}

141</script>

再就是页面了
 1<body>
 2    <form id="form1" runat="server">
 3    <!-- 今日天气 -->
 4<div ><h2 style="text-align: center">今日天气</h2></div>
 5<div style="text-align: center" >
 6<select name="sfweather1" onChange="sfsetcity1()">
 7<option selected value="">请选择省份</option>
 8<option value="独立直辖市">独立直辖市</option>
 9<option value="特别行政区">特别行政区</option>
10<option value="台湾">台湾</option>
11<option value="广东省">广东省</option>
12<option value="西藏">西藏</option>
13<option value="陕西省">陕西省</option>
14<option value="甘肃省">甘肃省</option>
15<option value="青海省">青海省</option>
16<option value="宁夏省">宁夏省</option>
17<option value="新疆">新疆</option>
18<option value="江苏省">江苏省</option>
19<option value="云南省">云南省</option>
20<option value="福建省">福建省</option>
21<option value="海南省">海南省</option>
22<option value="广西省">广西省</option>
23<option value="湖南省">湖南省</option>
24<option value="湖北省">湖北省</option>
25<option value="四川省">四川省</option>
26<option value="吉林省">吉林省</option>
27<option value="黑龙江">黑龙江</option>
28<option value="山东省">山东省</option>
29<option value="山西省">山西省</option>
30<option value="内蒙古">内蒙古</option>
31<option value="辽宁省">辽宁省</option>
32<option value="浙江省">浙江省</option>
33<option value="安徽省">安徽省</option>
34<option value="河南省">河南省</option>
35<option value="贵州省">贵州省</option>
36<option value="江西省">江西省</option>
37<option value="河北省">河北省</option>
38</select>
39<select name="sfweather1_1" id="sfweather1_1">
40            <option>请选择城市</option>
41          </select>
42<input name="button" type="button" value="定制" onclick="selectSubmit()"/>
43    <br />
44    当前天气城市:<label id="label1">广东省广州市</label></div>
45  
46        <table style="width: 586px" align=center>
47            <tr>
48                <td>
49        <iframe id="iframe1" src="http://www.weathercn.com/forecast/24time.jsp?sta_id=59287" style="width: 511px; height: 312px"></iframe>
50                </td>
51                <td>
52                <iframe id="iframe2" src=http://travel.163.com/weather/new/59287.html style="height: 305px"></iframe>
53                </td>
54            </tr>
55        </table>
56
57    </form>
58    
59
60</body>
posted on 2007-01-24 13:53  lovablebox  阅读(4578)  评论(0编辑  收藏  举报