首 页 ┆ 源码下载 ┆ IT学院 ┆ 字体下载 ┆ 模板下载 ┆ 源码发布 ┆ 广告合作 ┆ 网站地图 ┆ 虚拟主机 ┆ 中文域名
► 设为首页
► 加入收藏
► 联系我们
源码下载 >> ASP源码 | PHP源码 | ASP.net源码 | JSP源码 | CGI源码 | VC/C++源码 | VB源码 | Delphi源码 | Flash源码
文章学院 >> 网络编程 | 网页设计 | 图形图象 | 数据库 | 服务器 | 网络媒体 | 网络安全 | 操作系统 | 办公软件 | 软件开发 | 黑客知识
字体下载 >> 精制字体 | 非英字体 | 艺术字体 | 著名字体 | 哥特式 | 简单字体 | 手写体 | 节假日 | 图案字体 | 精度像素 | 中文字体
模板下载 >> 企业门户 | 数码网络 | 休闲娱乐 | 影视音乐 | 旅游名胜 | 文化艺术 | 电子商务 | 个性展示 | 登陆导航 | Flash模板
►►您当前的位置:源码园 → IT学院 → 网络编程 → NET专区 → 文章内容

用C#读取sina天气预报到wap页面(二)

作者:未知  来源:CSDN  发布时间:2007-2-6 17:11:15
 

public class weather : System.Web.UI.MobileControls.MobilePage
 {
  protected System.Web.UI.MobileControls.Label Label1;
  protected System.Web.UI.MobileControls.Label Label2;
  protected System.Web.UI.MobileControls.SelectionList s_weather;
  protected System.Web.UI.MobileControls.Label l_date;
  protected System.Web.UI.MobileControls.Label l_city;
  protected System.Web.UI.MobileControls.Label l_wea;
  protected System.Web.UI.MobileControls.Label l_sky;
  protected System.Web.UI.MobileControls.Label l_w1;
  protected System.Web.UI.MobileControls.Label l_w2;
  protected System.Web.UI.MobileControls.Label l_w3;
  protected System.Web.UI.MobileControls.Link Link1;
  protected System.Web.UI.MobileControls.Command Command1;
  protected System.Web.UI.MobileControls.Label Label3;
  protected System.Web.UI.MobileControls.Form Form1;

  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   if (!Page.IsPostBack)
   {
    string city = "深圳";
    int start,stop;
    string weather1,weather2,wea;
    string wea_city = weather_city(city);
    wea_city = wea_city.Replace(" ","");

    start = wea_city.IndexOf("<b>",0,wea_city.Length);
    stop = wea_city.IndexOf("</b>", start);
    weather1 = wea_city.Substring(start, stop-start).Trim() + "          ";
    weather1 = weather1.Substring(3,8).Trim();
   
    start = wea_city.IndexOf("<tdstyle=\"font-size:40px;font-family:TimesNewRoman;font-weight:bold;\">",0,wea_city.Length);
    stop = wea_city.IndexOf("℃",start) + 40;
    weather2 = wea_city.Substring(start, stop-start);
    weather2 = weather2.Substring(stop-start-42,40).Trim();
    weather2 = weather2.Replace("\t","");

    start = wea_city.IndexOf("<fontcolor=#183888><b>", 0, wea_city.Length);
    stop = wea_city.IndexOf("</b></font>",start);
    wea = wea_city.Substring(start,stop-start);
    wea = wea.Substring(22,wea.Length-22) + "kbrk";
    wea = wea.Replace("\t", "");
    wea = wea.Replace(">", "k");
    wea = wea.Replace("<", "k");
    wea = wea.Replace("kbrk", "k");
    string [] wall = null;
    char[] seperator = {'k'};
    wall = wea.Split(seperator);

    //////////////////////////////////////
    l_city.Text = "[城市]:" + city;
    l_wea.Text = "[天气]:" + weather1;
    l_sky.Text = "[温度]:" + weather2;
    ///////
    l_date.Text = wall[0];
    l_w1.Text = wall[1];
    l_w2.Text = wall[2];
    l_w3.Text = wall[3];
   }
  }

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }

  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.Command1.Click += new System.EventHandler(this.Command1_Click);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion


  private void Command1_Click(object sender, System.EventArgs e)
  {
   string city = s_weather.Selection.Value.Trim();
   int start,stop;
   string weather1,weather2,wea;
   string wea_city = weather_city(city);
   wea_city = wea_city.Replace(" ","");

   start = wea_city.IndexOf("<b>",0,wea_city.Length);
   stop = wea_city.IndexOf("</b>", start);
   weather1 = wea_city.Substring(start, stop-start).Trim() + "          ";
   weather1 = weather1.Substring(3,8).Trim();
   
   start = wea_city.IndexOf("<tdstyle=\"font-size:40px;font-family:TimesNewRoman;font-weight:bold;\">",0,wea_city.Length);
   stop = wea_city.IndexOf("℃",start) + 40;
   weather2 = wea_city.Substring(start, stop-start);
   weather2 = weather2.Substring(stop-start-42,40).Trim();
   weather2 = weather2.Replace("\t","");

   start = wea_city.IndexOf("<fontcolor=#183888><b>", 0, wea_city.Length);
   stop = wea_city.IndexOf("</b></font>",start);
   wea = wea_city.Substring(start,stop-start);
   wea = wea.Substring(22,wea.Length-22) + "kbrk";
   wea = wea.Replace("\t", "");
   wea = wea.Replace(">", "k");
   wea = wea.Replace("<", "k");
   wea = wea.Replace("kbrk", "k");
   string [] wall = null;
   char[] seperator = {'k'};
   wall = wea.Split(seperator);

   //////////////////////////////////////
   l_city.Text = "[城市]:" + city;
   l_wea.Text = "[天气]:" + weather1;
   l_sky.Text = "[温度]:" + weather2;
   ///////
   l_date.Text = wall[0];
   l_w1.Text = wall[1];
   l_w2.Text = wall[2];
   l_w3.Text = wall[3];  
  }

  public string weather_city(string city)
  {
   string temp = null;
   try
   {
    string strURL = "http://image2.sina.com.cn/dy/weather/images/figure/",0,HTML.Length);
    stop = HTML.IndexOf("<td background=http://image2.sina.com.cn/dy/weather/images",start);
    temp = HTML.Substring(start, stop - start);
   }
   catch (Exception x)
   {
   }
   return temp;
  }
 }



[] [返回上一页] [打 印]
  • 上一篇文章:C#获取本地计算机名,IP,MAC地址
  • 下一篇文章:用C#读取sina天气预报到wap页面(一)

  • 相关文章:
  • [图文]PrintSreen截取视频画面二法
  • 用C#读取sina天气预报到wap页面(一)
  • 用C#读取sina天气预报到wap页面(二)
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 源码发布
Copyright © 2003-2009 Ymyasp.Com. All Rights Reserved .
备案序号:粤ICP备07029071号