Implementation ideas:
1. Use the Java.net.URL object to bind the address of a Web page on a network
2. Obtain a Httpconnection object by using the OpenConnection () method of the Java.net.URL object
3. Obtain the input stream object of the network file through the getInputStream () method of the Httpconnection object InputStream
4. Loop through each row of data in the stream and compile the regular expression by the pattern object with each line of characters to get an email address
Key code:
Package Cn.bdqn;import Java.io.bufferedreader;import Java.io.inputstreamreader;import java.net.URL;import Java.net.urlconnection;import Java.util.regex.matcher;import Java.util.regex.pattern;public class Test {public static void Main (string[] args) throws Exception {//Create a URL object url url=new url (""); Open Connection URLConnection conn=url.openconnection (); Set the connection network timeout unit to milliseconds conn.setconnecttimeout (1000*10); Read the file in the specified network address by streaming operation BufferedReader Bufr=new BufferedReader (New InputStreamReader (Conn.getinputstream ())); String Line=null; Matches the email's regular String regex= "[a-za-z0-9_-][email protected]\\w+\\. [A-z]+ (\\.[ a-z]+)? "; Use the compile () method of the pattern to generate the pattern object, pattern p=pattern.compile (regex); while ((Line=bufr.readline ())!=null) {Matcher m=p.matcher (line); while (M.find ()) {System.out.println (M.group ()); } } }}
Java regular crawl email