一个简单的爬虫程序

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 网上下



 

posted on 2013-10-31 21:09  you Richer  阅读(358)  评论(0编辑  收藏  举报