获取yahoo的天气预报信息

2006年05月25日  |  6:20 下午分类:Develop  |  标签:  |  

下午弄出来的
准备用到blog上

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;

public partial class Default2 : System.Web.UI.Page
{
    protected string _content;
    protected void Page_Load(object sender, EventArgs e)
    {
        GetWebInfo web = new GetWebInfo(new UriBuilder(@"http://weather.cn.yahoo.com/area.html?city=%CE%E4%BA%BA"));

        _content = web.LinkFind();
    }
}
class GetWebInfo
{
    public String filetext;
    public GetWebInfo(UriBuilder url)
    {
        filetext = "";
        HttpWebRequest rs = (HttpWebRequest)WebRequest.Create(url.Uri);
        try
        {
            HttpWebResponse rsp = (HttpWebResponse)rs.GetResponse();

            using (StreamReader reader = new StreamReader(rsp.GetResponseStream(), System.Text.Encoding.Default))
            {
                String tmstr = "";
                while ((tmstr = reader.ReadLine()) != null)
                {
                    filetext += tmstr;
                }
            }
        }
        catch
        {
        }
    }
    public string  LinkFind()
    {
        Regex r;
        Match m;
        string _str = "";
            r = new Regex("<!--3-->\\s*(?<1>.*[^<])<!--3-->",
            RegexOptions.IgnoreCase | RegexOptions.Compiled);
        for (m = r.Match(filetext); m.Success; m = m.NextMatch())
        {
            _str+=m.Groups[1].ToString();
        }
        return _str;
    }
}
转载时务必以超链接形式标明文章原始出处和作者信息。

发表您的评论

1410168172122013183195114157619