Realize the idea:
1, using the Java.net.URL object, binding the address of a Web page on the network
2, through the Java.net.URL object OpenConnection () method to obtain a Httpconnection object
3, through the Httpconnection object's getInputStream () method obtains this network file the input stream object InputStream
4. Read each row of data in the stream, and the regular expression area compiled by pattern object with each line of characters, get the email address
package Cn.sdhzzl;
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
and network-related operations 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 IOException {//1.1 create a URL object url url = new URL ("https:/
/www.jb51.net/group/topic/8845032/");
1.2 Open Connection URLConnection conn = Url.openconnection ();
1.3 Setting the Connection Network timeout Unit is milliseconds conn.setconnecttimeout (1000 * 10);
1.4 reads the file in the specified network address through a stream operation BufferedReader bufr = new BufferedReader (New InputStreamReader (Conn.getinputstream ()));
String line = null; 1.5 regular String regex = "[a-za-z0-9_-]+@\\w+\\] matching email. [A-z]+ (\\.[
a-z]+)? ";
1.6 Use the Compile () method of the pattern to generate pattern P = pattern.compile (regex);
1.
while (line = Bufr.readline ())!= null) {Matcher m = p.matcher (line); while (M.find ()) {System.out.println (M.group ());//Get Matching Email}}}
Above this Java code crawl Web mailbox Implementation method is small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.