下午弄出来的
准备用到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;
}
}