• 抓取网页Email地址


     public class GetWebEmail
        {
            //抓取网页源代码
            public static List<string> GetHtmlAndEmail(string url)
            {
                //抓取网页内容
                string ContentHtml = String.Empty;

                HttpWebRequest httpWebRequest = null;
                HttpWebResponse httpWebResponse = null;
                Stream stream = null;
                StreamReader sr = null;

                httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                stream = httpWebResponse.GetResponseStream();
                Encoding encoding = Encoding.Default;
                sr = new StreamReader(stream, encoding);
                ContentHtml = sr.ReadToEnd();

                //将读取出来的全部URL写入文本文件 
                string fileName = HttpContext.Current.Server.MapPath(@"~/temp/EmailText.txt");//创建文本文档
                StreamWriter sw = File.AppendText(fileName);//创建写入流,这里是以追加的模式就行的


                //用正则表达式识别Email地址
                Regex EmailRegex = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                MatchCollection matches = EmailRegex.Matches(ContentHtml);
                List<string> list = new List<string>();
                foreach (Match match in matches)
                {
                    list.Add(match.Value.ToString());  //将数据添加到list
                    sw.WriteLine(match.Value.ToString());//将数据写入文件
                }
               

                sw.Close();
                sr.Close();
                stream.Close();
                httpWebResponse.Close();
                return list;
            }
        }

    //今天突然想起来实现抓取网页中的Email地址,这样可以去收集网络中的地址去打些广告不过这不是我的初衷,我只是突发奇想,想实现这个功能罢 了,以上类是我实现的抓取网页Email地址的方法,不过还没有将发送邮件的程序和该程序做练习,以前写过发送邮件的程序,有兴趣可以在我空间的日志中取 查找!有不对的地方请高手支出,共同提高……

  • 相关阅读:
    关于ip层的作用网址链接
    转载 TCPIP学习笔记之概述
    转载pll工作模式解析
    关于modelsim添加库的说明
    转载.Avalon-MM 阿窝龙妹妹应用笔记
    转载.怎样在Quartus II中转化HDL文件为bsf文件?
    niosii boot过程
    转载--傅里叶级数的几何意义 – 巧妙记忆公式的方法
    第十三篇:带缓冲的IO( 标准IO库 )
    第十二章:Linux中权限控制实例
  • 原文地址:https://www.cnblogs.com/wangsx/p/2039186.html
Copyright © 2020-2023  润新知