Home  >  Article  >  Database  >  JSP抓取网页代码的程序_MySQL

JSP抓取网页代码的程序_MySQL

WBOY
WBOYOriginal
2016-06-01 14:09:21847browse

  

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连接,然后再得到那个连接,然后再“抓”,不停止地(当然可以限定层数),这样,可以实现“网页搜索”功能。  

Statement:
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