码迷,mamicode.com
首页 > Web开发 > 详细

网页抓取邮箱

时间:2015-06-14 21:27:02      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;


namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            WebClient web = new WebClient();//抓取网页的类
            web.Encoding = Encoding.Default;//字符串编码方式
            string url = textBox1.Text.Trim();//去除输入网址的空格
            if (!string.IsNullOrEmpty(url))//判读输入网址是否为空
            {
                string html = web.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(@"E:\1.txt", sb.ToString());
                StreamWriter sw = new StreamWriter(@"E:\1.txt", true);//使用写入流保存到txt文档中
                sw.WriteLine(sb.ToString());
            }            
        }
    }
}

 

网页抓取邮箱

标签:

原文地址:http://www.cnblogs.com/happinesshappy/p/4575683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!