知识大全 ASP.Net获得新浪天气预报几种方式总结

Posted 风力

篇首语:策马前途须努力,莫学龙钟虚叹息。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 ASP.Net获得新浪天气预报几种方式总结相关的知识,希望对你有一定的参考价值。

ASP.Net获得新浪天气预报几种方式总结  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  刚赶工写了一个获取新浪天气预报的功能 顺便把代码分享了出来 以后再有这样的工作 大家可以直接把代码拿来使用  

   利用新浪提供给的iframe直接嵌入 这种方式非常的简单 但是却没有交互性 代码如下

  <iframe frameborder= src= scrolling= no width= height= ></iframe 抓取当天的天气 以指定格式输出

  涉及的核心代码如下

  Codepublic static ArrayList GetWeather(string code)                    /*            [ ] 北京 string            [ ] 雷阵雨 string            [ ] ℃ string            [ ] ℃ string            [ ] 小于 级 string            */            string = ;            try                            HttpWebRequest request = (HttpWebRequest)WebRequest Create( + code + l );                request Method = Get ;                //request Timeout   =   ;                request ContentType = application/x form urlencoded ;                WebResponse response = request GetResponse();                Stream s = response GetResponseStream();                StreamReader sr = new StreamReader(s System Text Encoding GetEncoding( GB ));                = sr ReadToEnd();                s Close();                sr Close();                        catch (Exception err)                            throw new Exception( 访问地址出错~~~ );           

  int count = Length;            int starIndex = IndexOf( <table count);            int endIndex = IndexOf( </table> starIndex count starIndex);            = Substring(starIndex endIndex starIndex + );

  //得到城市            int cityStartIndex = IndexOf( <b> Length);            int cityEndIndex = IndexOf( </b> Length);            string City = Substring(cityStartIndex + cityEndIndex cityStartIndex );

  //得到天气            int weatherStartIndex = IndexOf( <b> cityEndIndex);            int weatherEndIndex = IndexOf( </b> weatherStartIndex);            string Weather = Substring(weatherStartIndex + weatherEndIndex weatherStartIndex );

  //得到温度

  int temperatureStartIndex = IndexOf( <b weatherEndIndex);            int temperatureEndIndex = IndexOf( </b> weatherEndIndex + );            string Temperature = Substring(temperatureStartIndex + temperatureEndIndex temperatureStartIndex );

  int int = Temperature IndexOf( ℃ );            int int = Temperature IndexOf( ~ );            int int = Temperature IndexOf( ℃ int );

  string MinTemperature = Temperature Substring(int + int int );            string MaxTemperature = Temperature Substring( int int + );

  //得到风力            int windforceStartIndex = IndexOf( 风力 temperatureEndIndex);            int windforceEndIndex = IndexOf( <br> windforceStartIndex);            string Windforce = Substring(windforceStartIndex + windforceEndIndex windforceStartIndex );

  if (Windforce Contains( 小于 ) && (!Windforce Contains( 等于 )))                  //判断风力是否含有 小于 或 小于等于 字样将 如果有的话 将其替换为                             //Windforce = Windforce Replace( 小于 );                string strWindforce = Windforce Substring( Windforce Length );                int minWindforce = Int Parse(strWindforce) ;                Windforce = Windforce Replace( 小于 minWindforce ToString() + );

              else if (Windforce Contains( 小于等于 ))                            string strWindforce = Windforce Substring( Windforce Length );                int minWindforce = Int Parse(strWindforce) ;                Windforce = Windforce Replace( 小于等于 minWindforce ToString() + );           

  ArrayList al = new ArrayList();            al Add(City);            al Add(Weather);            al Add(MinTemperature);            al Add(MaxTemperature);            al Add(Windforce);

  return al;         这里涉及到一个ConvertCode类 它的作用是用于把城市转换为对应的全国统一的编码

  代码如下

  Codeusing System;using System Collections Generic;using System Web;

  namespace WebApplication     public class ConvertCode            public static string ConvertCodeByCity(string City)                    string Code = ;            switch (City)                            case 北京 :                    Code = ;                    break;                case 天津 :                    Code = ;                    break;                case 石家庄 :                    Code = ;                    break;                case 唐山 :                    Code = ;                    break;                case 秦皇岛 :                    Code = ;                    break;                case 张家口 :                    Code = ;                    break;                case 承德 :                    Code = ;                    break;                case 廊坊 :                    Code = ;                    break;                case 邯郸 :                    Code = ;                    break;                case 邢台 :                    Code = ;                    break;                case 保定 :                    Code = ;                    break;                case 沧州 :                    Code = ;                    break;                case 衡水 :                    Code = ;                    break;                case 太原 :                    Code = ;                    break;                case 大同 :                    Code = ;                    break;                case 阳泉 :                    Code = ;                    break;                case 晋城 :                    Code = ;                    break;                case 朔州 :                    Code = ;                    break;                case 忻州 :                    Code = ;                    break;                case 离石 :                    Code = ;                    break;                case 榆次 :                    Code = ;                    break;                case 临汾 :                    Code = ;                    break;                case 运城 :                    Code = ;                    break;                case 长治 :                    Code = ;                    break;                case 呼和浩特 :                    Code = ;                    break;                case 包头 :                    Code = ;                    break;                case 乌海 :                    Code = ;                    break;                case 集宁 :                    Code = ;                    break;                case 巴彦浩特 :                           //这个城市搜索不到                    Code = ;                    break;                case 临河 :                    Code = ;                    break;                case 鄂尔多斯 :                           //这个城市搜索不到                    Code = ;                    break;                case 赤峰 :                    Code = ;                    break;                case 通辽 :                    Code = ;                    break;                case 锡林浩特 :                    Code = ;                    break;                case 海拉尔 :                            //这个城市搜索不到                    Code = ;                    break;                case 乌兰浩特 :                    Code = ;                    break;                case 沈阳 :                    Code = ;                    break;                case 大连 :                    Code = ;                    break;                case 鞍山 :                    Code = ;                    break;                case 抚顺 :                    Code = ;                    break;                case 本溪 :                    Code = ;                    break;                case 锦州 :                    Code = ;                    break;                case 营口 :                    Code = ;                    break;                case 阜新 :                    Code = ;                    break;                case 盘锦 :                    Code = ;                    break;                case 铁岭 :                    Code = ;                    break;                case 朝阳 :                    Code = ;                    break;                case 葫芦岛 :                    Code = ;                    break;                case 丹东 :                    Code = ;                    break;                case 长春 :                    Code = ;                    break;                case 吉林 :                    Code = ;                    break;                case 四平 :                    Code = ;                    break;                case 辽源 :                    Code = ;                    break;                case 松原 :                    Code = ;                    break;                case 白城 :                    Code = ;                    break;                case 延边 :                    Code = ;                    break;                case 通化 :                    Code = ;                    break;                case 哈尔滨 :                    Code = ;                    break;                case 鸡西 :                    Code = ;                    break;                case 鹤岗 :                    Code = ;                    break;                case 双鸭山 :                    Code = ;                    break;                case 伊春 :                    Code = ;                    break;                case 佳木斯 :                    Code = ;                    break;                case 七台河 :                    Code = ;                    break;                case 牡丹江 :                    Code = ;                    break;                case 绥化 :                    Code = ;                    break;                case 齐齐哈尔 :                    Code = ;                    break;                case 大庆 :                    Code = ;                    break;                case 黑河 :                    Code = ;                    break;                case 大兴安岭 :                    Code = ;                    break;                case 上海 :                    Code = ;                    break;                case 南京 :                    Code = ;                    break;                case 无锡 :                    Code = ;                    break;                case 徐州 :                    Code = ;                    break;                case 常州 :                    Code = ;                    break;                case 苏州 :                    Code = ;                    break;                case 南通 :                    Code = ;                    break;                case 连云港 :                    Code = ;                    break;                case 淮阴 :                    Code = ;                    break;                case 盐城 :                    Code = ;                    break;                case 扬州 :                    Code = ;                    break;                case 镇江 :                    Code = ;                    break;                case 泰州 :                    Code = ;                    break;                case 宿迁 :                    Code = ;                    break;                case 杭州 :                    Code = ;                    break;                case 宁波 :                    Code = ;                    break;                case 温州 :                    Code = ;                    break;                case 嘉兴 :                    Code = ;                    break;                case 湖州 :                    Code = ;                    break;                case 绍兴 :                    Code = ;                    break;                case 金华 :                    Code = ;                    break;                case 衢州 :                    Code = ;                    break;                case 舟山 :                    Code = ;                    break;                case 丽水 :                    Code = ;                    break;                case 台州 :                    Code = ;                    break;                case 合肥 :                    Code = ;                    break;                case 芜湖 :                    Code = ;                    break;                case 蚌埠 :                    Code = ;                    break;                case 淮南 :                    Code = ;                    break;                case 马鞍山 :                    Code = ;                    break;                case 淮北 :                    Code = ;                    break;                case 铜陵 :                    Code = ;                    break;                case 安庆 :                    Code = ;                    break;                case 黄山市 :                    Code = ;                    break;                case 阜阳 :                    Code = ;                    break;                case 宿州 :                    Code = ;                    break;                case 滁州 :                    Code = ;                    break;                case 六安 :                    Code = ;                    break;                case 宣城 :                    Code = ;                    break;                case 巢湖 :                    Code = ;                    break;                case 池州 :                    Code = ;                    break;                case 福州 :                    Code = ;                    break;                case 厦门 :                    Code = ;                    break;                case 莆田 :                    Code = ;                    break;                case 三明 :                    Code = ;                    break;                case 泉州 :                    Code = ;                    break;                case 漳州 :                    Code = ;                    break;                case 南平 :                    Code = ;                    break;                case 宁德 :                    Code = ;                    break;                case 龙巖 :                    Code = ;                    break;                case 陇南 :                    Code = ;                    break;                case 庆阳 :                    Code = ;                    break;                case 南昌 :                    Code = ;                    break;                case 景德镇 :                    Code = ;                    break;                case 赣州 :                    Code = ;                    break;                case 萍乡 :                    Code = ;                    break;                case 九江 :                    Code = ;                    break;                case 新余 :                    Code = ;                    break;                case 鹰潭 :                    Code = ;                    break;                case 宜春 :                    Code = ;                    break;                case 上饶 :                    Code = ;                    break;                case 吉安 :                    Code = ;                    break;                case 济南 :                    Code = ;                    break;                case 青岛 :                    Code = ;                    break;                case 淄博 :                    Code = ;                    break;                case 枣庄 :                    Code = ;                    break;                case 东营 :                    Code = ;                    break;                case 烟台 :                    Code = ;                    break;                case 潍坊 :                    Code = ;                    break;                case 济宁 :                    Code = ;                    break;                case 泰安 :                    Code = ;                    break;                case 威海 :                    Code = ;                    break;                case 日照 :                    Code = ;                    break;                case 滨州 :                    Code = ;                    break;                case 德州 :                    Code = ;                    break;                case 聊城 :                    Code = ;                    break;                case 临沂 :                    Code = ;                    break;                case 菏泽 :                    Code = ;                    break;                case 莱芜 :                    Code = ;                    break;                case 郑州 :                    Code = ;                    break;                case 开封 :                    Code = ;                    break;                case 洛阳 :                    Code = ;                    break;                case 平顶山 :                    Code = ;                    break;                case 安阳 :                    Code = ;                    break;                case 鹤壁 :                    Code = ;                    break;                case 新乡 :                    Code = ;                    break;                case 焦作 :                    Code = ;                    break;                case 濮阳 :                    Code = ;                    break;                case 许昌 :                    Code = ;                    break;                case 漯河 :                    Code = ;                    break;                case 三门峡 :                    Code = ;                    break;                case 商丘 :          &

相关参考

知识大全 ASP.NET页面之间传递值的几种方式

ASP.NET页面之间传递值的几种方式  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! &

知识大全 asp.net下载文件几种方式

   一//TransmitFile实现下载      protectedvoidButton_Click(o

知识大全 ASP.NET缓存总结

ASP.NET缓存总结  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  一缓存概念缓存的好处类型 

知识大全 ASP.NET定时发送邮件总结

ASP.NET定时发送邮件总结  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  香港那边公司的市场

知识大全 ASP.NET中的STREAMREADER对象总结

ASP.NET中的STREAMREADER对象总结  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 

知识大全 ASP.NET页面打印技术的总结

ASP.NET页面打印技术的总结  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  网络打印概述  

知识大全 asp.net导出Excel方法总结

asp.net导出Excel方法总结  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! &n

知识大全 Asp.NET大文件上传开发总结(二)

Asp.NET大文件上传开发总结(二)  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  为了提供文

知识大全 Asp.NET大文件上传开发总结(一)

Asp.NET大文件上传开发总结(一)  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  以前开发过

知识大全 asp.net 页面跳转

  跳转方式有以下几种  Hyperlink控件跳转  服务器传输  Servertransfer  浏览器重定向  HttpResponseRedirect  跨页发送  PreviousPage