java爬取网页上qq号,邮箱号等

直接拷贝代码执行即可(前提是能连上网络)

结果输出在控制台

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GetMail {
public static void main(String[] args) throws Exception {
//getMails();
getMails_url();
}

public static void getMails_url() throws Exception {
URL url = new URL("https://");//这里就是要爬取的网页
URLConnection conn = url.openConnection();
BufferedReader bufr = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = null;
String maileRes = "[\u4E00-\u9FA5]+";//这里存放需要设定的规则

//匹配邮箱:"\\w+@\\w+(\\.\\w+)+"
//匹配汉字:"[\u4E00-\u9FA5]+";
//匹配QQ号:"[1-9][0-9]{4,14}"
//qq邮箱:"(.)+@(.)+(\\.[a-z]+){1,}";
Pattern p = Pattern.compile(maileRes);


while((line=bufr.readLine())!=null) {
Matcher m = p.matcher(line);
while(m.find()) {
System.out.println(m.group());
}

}
}

上一篇:Java正则表达式


下一篇:【Java设计模式】Java设计模式之(二十二)外观模式(Facade Pattern)