网络蜘蛛,收集网页中的邮箱地址信息。(正则表达式)
import java.io.FileInputStream; import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; public class spider { public static void main(String[] args) { String mailReg="\\w+@\\w+(\\.\\w+)+"; Pattern p=Pattern.compile(mailReg); try { FileInputStream in=new FileInputStream("./spider.html"); byte buf[]=new byte[1024]; int len=0; while((len=in.read(buf))!=-1){ String str=new String(buf,0,len); Matcher m=p.matcher(str); while(m.find()){ System.out.println(m.group()); } } } catch (IOException e) { e.printStackTrace(); } } }以下是文件spider.html部分(从www.hncu.net获取)
湖南城市学院