zoukankan      html  css  js  c++  java
  • 实现天气预报类···························

    public ArrayList GetWeather(string code)
    {
    /*
    [0]"今日天气"string
    [1]"北京"string
    [2]"<img src=http://image2.sina.com.cn/dy/weather/images/figure/leizhenyu_big.gif width=45 height=45 alt=雷阵雨>"string
    [3]"雷阵雨"string
    [4]"29℃~21℃"string
    [5]"2006年7月27日-28日"string
    [6]" 风力:小于3级"string
    [7]"空气质量:良 "string
    [8]"紫外线强度:弱 "string
    */
    string html = string.Empty;
    try
    {
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://weather.sina.com.cn/iframe/weather/"+code+"_w.html");
    request.Method = "Get";
    //request.Timeout = 1;
    request.ContentType = "application/x-www-form-urlencoded";
    WebResponse response = request.GetResponse();
    Stream s = response.GetResponseStream();
    StreamReader sr = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
    html = sr.ReadToEnd();
    s.Close();
    sr.Close();
    }
    catch
    {
    throw new Exception("访问地址出错~~~");
    }
    int count = html.Length;
    int starIndex = html.IndexOf("<table ",0,count-1);
    int endIndex = html.IndexOf("</table>",starIndex,count-starIndex-1);
    html = html.Substring(starIndex,endIndex-starIndex+8);
    html = Regex.Replace(html,"<br/>|</td>","|");
    html = Regex.Replace(html,"<[^img][^>]*>","");
    html = Regex.Replace(html,"\t|\r|\n","");
    string [] strWeather = html.Split('|');
    ArrayList array = new ArrayList();
    foreach(string strTemp in strWeather)
    {
    if(strTemp != "")
    array.Add(strTemp);
    }
    return array;
    }
  • 相关阅读:
    利用pipe实现进程通信一例
    司机和售票员问题 信号signal注册一例
    HDU 1003
    HDU 1847
    HDU 1846(巴什博弈)
    《断弦》感想
    夺冠概率
    熄灯问题
    HDU 2176(Nim博弈)
    NYOJ 541
  • 原文地址:https://www.cnblogs.com/Fooo/p/616566.html
Copyright © 2011-2022 走看看