Home > Database > Mysql Tutorial > body text

JSP抓取网页代码的程序_MySQL

WBOY
Release: 2016-06-01 14:09:21
Original
846 people have browsed it

  

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();  

l_connection.connect();  

l_urlStream = l_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);  

%>

后记  

  虽然代码比较简单,但是,我认为根据这个,可以实现“网络爬虫”的功能,比如从页面找href连接,然后再得到那个连接,然后再“抓”,不停止地(当然可以限定层数),这样,可以实现“网页搜索”功能。  

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!