11 Java/jsp Learning Series (simple "webpage capture" code)

Source: Internet
Author: User
I. Preface

From a website, I saw a code "webpage capture", which was a bit interesting, but did not provide the source code. So I wanted to write it myself. In fact, the code is relatively simple.

Ii. Code

<% @ Page contenttype = "text/html; charset = gb2312" %>

<%

String scurrentline;

String stotalstring;

Scurrentline = "";

Stotalstring = "";

Java. Io. inputstream l_urlstream;

Java.net. url l_url = new java.net. URL ("http://www.163.net /");

Java.net. httpurlconnection l_connection = (java.net. httpurlconnection) l_url.openconnection ();

Rochelle connection.connect ();

Rochelle urlstream = Rochelle connection.getinputstream ();

Java. Io. bufferedreader l_reader = new java. Io. bufferedreader (New java. Io. inputstreamreader (l_urlstream ));

While (scurrentline = l_reader.readline ())! = NULL)

{

Stotalstring + = scurrentline;

}

Out. println (stotalstring );

%>

Iii. Postscript

Although the Code is relatively simple, I think the "web crawler" function can be implemented based on this, for example, finding an href connection from the page, then getting the connection, and then "capturing ", do not stop (of course, you can limit the number of layers). In this way, you can implement the "Webpage Search" function.

Related Article

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.