One: Crawl the email address in the webpage
Using regular expressions to match text in a Web page
[\\w[.-]]+@[\\w[.-]]+\\. [\\w]+
Split the page content to extract
import java.io.BufferedReader; import java.io.FileNotFoundException; import
Java.io.FileReader;
Import java.io.IOException;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern; public class Emailspider {public static void main (string[] args) {try {bufferedreader br = new Bufferedrea
Der (New FileReader ("c:\\emailspider.html"));
String line = "";
while ((Line=br.readline ())!= null) {parse (line);
} catch (FileNotFoundException e) {e.printstacktrace ();
catch (IOException e) {e.printstacktrace (); } private static void Parse (String line) {Pattern p = pattern.compile ("[\\w[.-]]+@[\\w[.-]]+\\.[
\\w]+ ");
Matcher m = p.matcher (line);
while (M.find ()) {System.out.println (M.group ()); }
}
}
Print results:
867124664@qq.com
260678675@QQ.com
806208721@qq.com
Hr_1985@163.com
32575987@qq.com
Qingchen0501@126.com
Yingyihanxin@foxmail.com
1170382650@qq.com
1170382650@qq.com
Yingyihanxin@foxmail.com
Qingchen0501@126.com
32575987@qq.com
Hr_1985@163.com
Now you find so many email addresses, with the knowledge of JavaMail, you can send mass spam, hehe!!!
Two: Code statistics
Import Java.io.BufferedReader;
Import Java.io.File;
Import java.io.FileNotFoundException;
Import Java.io.FileReader;
Import java.io.IOException; public class Codecounter {static Long normallines = 0;//Normal code line static long Commentlines = 0;//Comment Line static long whi Telines = 0;//blank line public static void main (string[] args) {//Find a folder in which there are no folders, no write recursion for files not in the same folder file F
= new File ("E:\\workspaces\\eclipse\\application\\javamailtest\\src\\com\\java\\mail");
file[] Codefiles = F.listfiles ();
for (file child:codefiles) {///Statistics only Java file if (Child.getname (). Matches (". *\\.java$")) {parse (child);
} System.out.println ("Normallines:" + normallines);
System.out.println ("Commentlines:" + commentlines);
System.out.println ("Whitelines:" + whitelines);
private static void Parse (File f) {bufferedreader br = null;
Indicates whether to start Boolean comment = False for the comment; try {br = new BufferedReader (new FileReader (f));
String line = "";
while (line = Br.readline ())!= null) {//Remove the blank line = Line.trim () that may appear before the annotation character/*; Empty line because ReadLine () has removed the string, the newline character \ n//So is not "^[\\s&&[^\\n]]*\\n$" if (line.matches) ("^[\\s&&[
^\\n]]*$ ")) {whitelines + +;
else if (Line.startswith ("*") &&!line.endswith ("* *")) {//statistic multiline/*****/Commentlines + +;
Comment = true;
else if (Line.startswith ("*") && line.endswith ("* *")) {//statistic row/**/Commentlines + +;
else if (true = = comment) {//Statistics */commentlines + +;
if (Line.endswith ("* *")) {comment = false;
} else if (Line.startswith ("//)") {commentlines + +;
else {normallines + +;
A catch (FileNotFoundException e) {e.printstacktrace ());
catch (IOException e) {e.printstacktrace (); } finAlly {if (br!= null) {try {br.close ();
br = NULL;
catch (IOException e) {e.printstacktrace ();
}
}
}
}
}
The
Above is a simple application for Java regular expressions, and hopefully it will help you learn Java regular expressions.