热门:网页模板.net视频教程JQueryMVCjsonExtJs源码示例三级联动JQuery菜单
您现在的位置:.Net中文社区>> .Net编程>>正文内容

获取天气信息

发布时间:2009年11月02日点击数: xiaoxiaoniao

/// 得到天气数据
    ///
    /// 数组(0、天气;1、气温;2、风力;3、紫外线;4、空气)
    public static string[] GetWeather()
    {
        Regex regex;
      
        string[] weather = new string[5];
        string content = "";
        
        Match mcTmp;
        Match mcCity;
        int k = 1;

        HttpWebResponse theResponse;
        WebRequest theRequest;


        theRequest = WebRequest.Create("http://weather.news.qq.com/inc/ss82.htm");
        try
        {
            theResponse = (HttpWebResponse)theRequest.GetResponse();

/// 得到天气数据
    ///
    /// 数组(0、天气;1、气温;2、风力;3、紫外线;4、空气)
    public static string[] GetWeather()
    {
        Regex regex;
      
        string[] weather = new string[5];
        string content = "";
        
        Match mcTmp;
        Match mcCity;
        int k = 1;

        HttpWebResponse theResponse;
        WebRequest theRequest;


        theRequest = WebRequest.Create("http://weather.news.qq.com/inc/ss82.htm");
        try
        {
            theResponse = (HttpWebResponse)theRequest.GetResponse();

using (System.IO.Stream sm = theResponse.GetResponseStream())
            {
                System.IO.StreamReader read = new System.IO.StreamReader(sm, Encoding.Default);
                content = read.ReadToEnd();
            }

        }

        catch (Exception)
        {
            content = "";
        }

    

        string parttenTmp = "(?[^";
        k = 1;
        regex = new Regex(parttenTmp, RegexOptions.Compiled | RegexOptions.IgnoreCase);
        for (mcTmp = regex.Match(content), k = 1; mcTmp.Success; mcTmp = mcTmp.NextMatch(), k++)
        {

            weather[0] = mcTmp.Groups["item1"].Value;
        }

        parttenTmp = "height=\"23\" align=\"center\">(?[^/]+)";
        k = 1;
        regex = new Regex(parttenTmp, RegexOptions.Compiled | RegexOptions.IgnoreCase);
        for (mcTmp = regex.Match(content), k = 1; mcTmp.Success; mcTmp = mcTmp.NextMatch(), k++)
        {
            weather[k] = mcTmp.Groups["item1"].Value;
        }

        return weather;
    }

本站热点业务

更多模板/案例展示

关于我们 | 联系我们 | 团队日志 | 网站地图 | 网站合作