使用方法:把自己在网上保存下来含有邮箱的网页所在硬盘的路径,拷到对应位置即可,此程序用eclipse-luna-64位测试已通过
程序最终来源为马上兵老师发布的视频及源码,本人是用来学习,并和大家分享
视频链接:http://pan.baidu.com/s/1jIE5qC2 密码:fg75
import java.io.BufferedReader;import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 文件名:EmailSpider.java
* 时间:2017年2月18日下午1:24:27
* 作者:
* 功能:抓取网页上的邮箱
*/
public class EmailSpider {
public static void main(String[] args) {
try{
BufferedReader br = new BufferedReader(new FileReader("E:/Java/Eclipse/Study/src/cn/xcu/edu/regexp/tt.htm"));
String line = "";
while((line=br.readLine())!= null) {
parse(line);
}
br.close();
}catch (FileNotFoundException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void parse(String line) {
Pattern p = Pattern.compile("[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+");
Matcher m = p.matcher(line);
while(m.find()){
System.out.println(m.group());
}
}
}