网页抓取邮箱
2015-06-14 20:46
411 查看
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()); } } } }
相关文章推荐
- [ATL/WTL]_[初级]_[转发消息让CStatic支持点击消息操作]
- Android 性能优化(一)
- 树莓派实验一:控制LED灯
- [ATL/WTL]_[初级]_[转发消息让CStatic支持点击消息操作]
- 如何解决NO EPCS LAYOUT DATA --- LOOKING FOR SECTION [EPCS-XXXXXX]
- git获取 bitbucket 项目
- Android 系统稳定性 - OOM
- Core file 文件格式(Linux Coredump文件结构)
- [每周一题]Edit Distance from LeetCode
- 黑马程序员---Java基础-String类
- 【mysql5.6】连接vs2010
- poj 1654 Area
- QtPropertyBrowser 下载地址
- C++复制构造函数和赋值符的区别
- spring实战四之Bean的自动装配(注解方式)
- 软件设计入门2 数据库设计
- LVS负载均衡
- Linux网络服务器配置——认证网站某目录的方法
- 第十五周 项目一:用二进制文件处理学生成绩
- 在vs2013+qt中添加控制台