六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 59|回复: 0

正则表达式抓取网页的所有邮箱链接

[复制链接]

升级  18%

19

主题

19

主题

19

主题

秀才

Rank: 2

积分
77
 楼主| 发表于 2013-2-7 15:37:09 | 显示全部楼层 |阅读模式
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;/** * 正则表达式抓取网页的所有邮箱链接 * @author chase * */public class EmailSpider {public static void main(String args[]) {try {BufferedReader br = new BufferedReader(new FileReader("E:\\test\\*.html"));String line = "";while ((line = br.readLine()) != null) {parse(line);}} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}/** 用正则表达式判断并显示email 地址 */public 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());}}} 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表