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;
    }
  • 相关阅读:
    Android开发之Sqlite的使用
    ZOJ 3607 Lazier Salesgirl
    ZOJ 3769 Diablo III
    ZOJ 2856 Happy Life
    Ural 1119 Metro
    Ural 1146 Maximum Sum
    HDU 1003 Max Sum
    HDU 1160 FatMouse's Speed
    Ural 1073 Square Country
    Ural 1260 Nudnik Photographer
  • 原文地址:https://www.cnblogs.com/Fooo/p/616566.html
Copyright © 2011-2022 走看看