After learning the regular, intend to play with Java, so decided to use it to achieve a fun idea
ImportJava.io.BufferedReader;Importjava.io.IOException;ImportJava.io.InputStreamReader;//Network-related operationsImportJava.net.URL;Importjava.net.URLConnection;ImportJava.util.regex.Matcher;ImportJava.util.regex.Pattern;/*** Regular Crawl mailbox *@authorBig Peng **/ Public classTest { Public Static voidMain (string[] args)throwsIOException {//1.1 Let's start by creating a URL objectURL url =NewURL ("//need to write a Web page with an email address.")); //1.2 Opening the connectionURLConnection conn =url.openconnection (); //1.3 Setting the connection network time-out unit to millisecondsConn.setconnecttimeout (1000 * 10); //1.4 reading a file from a specified network address through a stream operationBufferedReader BUFR =NewBufferedReader (NewInputStreamReader (Conn.getinputstream ())); String Line=NULL; //1.5 match the regular of the email address, do not understand it's okay, just know that it matches the email address.String regex = "[A-za-z0-9_-][email protected]\\w+\\. [A-z]+ (\\.[ a-z]+)? "; //1.6 Generating Pattern objects using the compile () method of the patternPattern p =pattern.compile (regex); //1. while(line = Bufr.readline ())! =NULL) {Matcher m=P.matcher (line); while(M.find ()) {System.out.println (M.group ());//get a matching email } } }}
capture all email addresses in the web
Walk past Don't miss the ~java language crawl page want content