How to implement Java code crawl Web mailbox _java

Source: Internet
Author: User

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.

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.