private void Page_Load(object sender, System.EventArgse)
{
//在此處放置使用者代碼以初始化頁面
string url =http://www.jb51.net;
System.Net.HttpWebRequesthttpReq;
System.Net.HttpWebResponsehttpRes;
System.UrihttpURL = new Uri(url);
httpReq =(System.Net.HttpWebRequest)System.Net.WebRequest.Create(httpURL);
httpReq.Method= "GET";
httpRes= (System.Net.HttpWebResponse)httpReq.GetResponse();
httpReq.KeepAlive= false;
System.IO.StreamReadersReader = newSystem.IO.StreamReader(httpRes.GetResponseStream(),System.Text.Encoding.GetEncoding("GB2312"));
stringres = sReader.ReadToEnd();
//以下是利用Regex對擷取的文字資料流進行過濾
stringstrRegex = @"<a.+?a>";
System.Text.RegularExpressions.Regexr;
System.Text.RegularExpressions.MatchCollectionm;
r = newSystem.Text.RegularExpressions.Regex(strRegex,System.Text.RegularExpressions.RegexOptions.IgnoreCase);
m =r.Matches(res);
Response.Write("該頁共有"+m.Count + " 個超串連<br/>");
for (inti = 0; i < m.Count; i++)
{
Response.Write(m[i].Value+ "<br/>");
}
}