using System.Text.RegularExpressions;
using System.IO;
using System.Net;
// 获取网页html代码
string html = GetPageHtml("http://www.dz37w.com","gb2312");
// 获取网页所有email
Regex regex = new Regex(@"([A-Z0-9a-z]+([-+.][A-Z0-9a-z]+)*@[A-Z0-9a-z]+([-.][A-Z0-9a-z]+)*\.[A-Z0-9a-z]+([-.][A-Z0-9a-z]+)*)");
MatchCollection match = regex.Matches(html);
for (int i = 0;i < match.Count;i++)
{
if (match[i].Success)
{
Response.Write(match[i].Groups[0].Value + "<br>");
}
}
//用户自定义函数
protected string GetPageHtml(string url, string charset)
{
WebRequest request = WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream ();
StreamReader reader = new System.IO.StreamReader(dataStream, System.Text.Encoding.GetEncoding(charset));
string pageHtml = reader.ReadToEnd ();
reader.Close ();
dataStream.Close ();
response.Close ();
return pageHtml;
}
请注意,自行修改根据目标网址修改"gb2312"编码;