package cn.dhj;
import java.io.*;
import java.net.*;
import java.util.regex.*;
/*
* 网页爬虫,从网页中获取信息
*/
public class RegexTest {
public static void main(String[] args) throws Exception{
getmails();
}
public static void getmails() throws Exception{
URL url = new URL("http://www.9u8u.com/yxzt/25684.html");
URLConnection conn = url.openConnection();
BufferedReader buffIn = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = null;
String reg = "\\w+@\\w+(\\.\\w+)+";
Pattern p = Pattern.compile(reg);
while((line = buffIn.readLine())!=null){
Matcher m = p.matcher(line);
while(m.find()){
System.out.println(m.group());
}
}
}
}
|
|