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爬取网页上qq号,邮箱号等

上一篇:Redis学习笔记~是时候为Redis实现一个仓储了,RedisRepository来了


下一篇:Python模拟登陆新浪微博