代码改变世界

从网页上抓取邮箱

2012-03-28 20:28  shy_carson  阅读(331)  评论(0)    收藏  举报

我是一名初学者.这是我自己写的从网页上抓取邮箱的C#代码!有什么更好的请大家指出,这是用WinFor做的.同时保存到磁盘中

WebClient wc = new WebClient();
wc.Encoding = Encoding.Default;
string url = textBox1.Text.Trim();
if (string.IsNullOrEmpty(url))
{
return;
}
string html = wc.DownloadString(url);
MatchCollection mc = Regex.Matches(html,@"[a-zA-Z0-9_\-\.]+@\w+(\.\w+)+" );
StringBuilder sb = new StringBuilder();
foreach (Match m in mc)
{
sb.AppendLine(m.Value);
}
textBox2.Text = sb.ToString();
File.WriteAllText("D:\\1.txt",sb.ToString());