当前位置:
编程学习 >
JAVA >>
网络爬虫代码实例(java程序)
Java代码
- package cn.xuediit.netPaBug;
-
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
-
- /*@src http://eric-619.javaeye.com/blog/693741*/
- public class NetBug{
- public static void main(String[] args){
- new NetBug().methodPa("http://www.baidu.com");
- }
-
- public void methodPa(String strURL){
- String temp;
- try{
- URL url = new URL(strURL);
- HttpURLConnection conn = (HttpURLConnection)url.openConnection();
- InputStreamReader isr = new InputStreamReader(conn.getInputStream());
- BufferedReader br = new BufferedReader(isr);
- while((temp = br.readLine()) != null){
- System.out.println(temp);
- }
- br.close();
- isr.close();
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- }
补充:软件开发 , Java ,