zoukankan      html  css  js  c++  java
  • 一个简单的爬虫程序

    import org.apache.commons.httpclient.HttpClient;
    import org.apache.commons.httpclient.HttpStatus;
    import org.apache.commons.httpclient.methods.GetMethod;
    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
     
    public class Test1 {
     
        public static void main(String[] args)throws Exception {
            //String url="http://www.baidu.com";
            String url="http://10.137.13.61:9000/dashboard/index/1";
            HttpClient client=new HttpClient();
            //PostMethod method=new PostMethod(url);
            GetMethod method=new GetMethod(url);
            int status=client.executeMethod(method);
            if(status==HttpStatus.SC_OK){
                String html=method.getResponseBodyAsString();
                Document doc=Jsoup.parse(html);
                System.out.println(doc.toString());
            }else{
                System.err.println("URL Exception");
            }
        }
    }

    commons-httpclient-3.1.zip :   http://mirrors.hust.edu.cn/apache/httpcomponents/commons-httpclient/binary/

    另外需要commons-logging-1.1.3.jar   commons-codec-1.6.jar  jsoup-1.7.2.jar 网上下



  • 相关阅读:
    【JAVA
    【Android
    【开发工具
    【开发工具
    【开发工具
    【Android
    【Android
    【JavaEE】之MyBatis查询缓存
    【JavaEE】之MyBatis逆向工程的使用
    新的起点 Entry KINGSOFT
  • 原文地址:https://www.cnblogs.com/riskyer/p/3400163.html
Copyright © 2011-2022 走看看