protected void Page_Load(object sender, EventArgs e)
{
string inputString = getHtml("http://www.sina.com.cn/");
StringBuilder sb = new StringBuilder();
Regex reg = null;
Match mch = null;
reg = new Regex(@"<a[^<>]*?hrefs*=s*['""s]([^""']*)['""][^<>]*?>(.*?)</a>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
for (mch = reg.Match(inputString); mch.Success; mch = mch.NextMatch())
{
sb.AppendLine("网站:" + mch.Groups[2] + " ");
sb.AppendLine("地址:" + mch.Groups[1] + "</br>");
}
Response.Write(sb.ToString());
}
private string getHtml(string url)
{
WebClient myWebClient = new WebClient();
byte[] myDataBuffer = myWebClient.DownloadData(url);
return Encoding.Default.GetString(myDataBuffer);
}