正则表达式抓取网页中的邮箱地址
发布时间:2020-12-14 01:29:43 所属栏目:百科 来源:网络整理
导读:最近为了给博友分享资源,不得不利用一下了。下次再谈怎么自动发送带附件的邮件到目标邮箱地址。 上代码非常简单 :把网页源代码copy到new.txt文件下就OK了。 import java.io.*;import java.util.*;import java.util.regex.Matcher;import java.util.regex.P
最近为了给博友分享资源,不得不利用一下了。下次再谈怎么自动发送带附件的邮件到目标邮箱地址。 上代码非常简单 :把网页源代码copy到new.txt文件下就OK了。 import java.io.*; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class getEmail { public static void main(String[] args) throws Exception { FileReader fr = new FileReader("E:new.txt"); BufferedReader bf = new BufferedReader(fr); String str = ""; StringBuilder strb = new StringBuilder(); while((str = bf.readLine()) != null) { strb.append(str); str = ""; } Pattern p = Pattern.compile("w{3,20}@w+.(com|gov|net|org)"); Matcher m = p.matcher(strb); while(m.find()) { System.out.println(m.group()); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |