请问如何使用java程序通过一个网页地址,把网页里面的内容获取? 
类是网络爬虫的功能!

解决方案 »

  1.   

    InputStream is = (new java.net.URL("http://...")).openStream();
    is.read();
      

  2.   

    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;public class GetCode { public static String getCode(String webUrl){
     String Line = "";
    try {
    InputStream  in;
    URL url = new java.net.URL(webUrl);
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    connection = (HttpURLConnection) url.openConnection();
    //模拟成IE
    connection.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");
    connection.connect();
    in = connection.getInputStream();
        java.io.BufferedReader breader = new BufferedReader(new InputStreamReader(in , "GBK"));           while(breader.readLine() != null){
           Line +=breader.readLine();
           System.out.println(Line);
          }
    } catch (Exception e) {
    e.printStackTrace();
    }
    return Line;
    }
    public static void main(String[] args) {
    String http = "http://www.easydone.cn/index.htm";
    System.out.println(getCode(http));
    }
    }
      

  3.   

    InputStream is = (new java.net.URL("http://...")).openStream();
    is.read();
    先这样...然后你去看你要抓取的网页代码..把你要提取内容的标签记下,这样就可以了.
      

  4.   

    用javascript ajax 也可以的