[Stick to the top] Java case 1 web crawler obtains the email address

Source: Internet
Author: User

Preface: I have compiled some useful java files.Program. This is a simple Web Crawler to get the email address.

 

Package COM. lianggzone. demo; import Java. io. ioexception; import Java. io. inputstream; import java.net. httpurlconnection; import java.net. URL; import Java. util. regEx. matcher; import Java. util. regEx. pattern;/*** the web crawler obtains the email address * @ author lianggzone */public class emailspider {public static void main (string [] ARGs) {URL url = NULL; string RegEx = "[\ W [. -] + @ [\ W [. -] + \\. [\ W] + "; string tempstr = NULL; pattern = pattern. compile (RegEx); matcher = NULL; try {// get URL url = new URL ("http://zhidao.baidu.com/question/92607106.html"); // connect URL address httpurlconnection urlconnection = (httpurlconnection) URL. openconnection (); urlconnection. connect (); // define the input stream inputstream in = urlconnection. getinputstream (); byte [] Buf = new byte [4096]; while (in. read (BUF)> 0) {tempstr = new string (BUF); matcher = pattern. matcher (tempstr); While (matcher. find () {system. out. println (matcher. group () ;}} catch (ioexception e) {e. printstacktrace ();}}}

Note: here there is a link to the database, not the GUI interface, then, modify the url = new URL ("http://zhidao.baidu.com/question/92607106.html"); change to the address you want.

 

 

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.