Walk past Don't miss the ~java language crawl page want content

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.