首页 > 编程语言 > 详细

简单JAVA爬虫

时间:2015-06-27 21:19:22      阅读:274      评论:0      收藏:0      [点我收藏+]

Apache官网下载httpcomponents-client-4.4,在项目中导入jar

主要类:HttpClient,HttpGet,HttpResponse,HttpEntity

public static void getContentFromUrl(String url) {
    HttpClient client = new DefaultHttpClient();
    HttpGet getHttp = new HttpGet(url);
    while (true) {
        try {
            HttpResponse response = client.execute(getHttp);
            HttpEntity entity = response.getEntity();
            String content = null;
            String str = null;
            if (entity != null) {
                content = EntityUtils.toString(entity);
                str = new String(content.getBytes("ISO-8859-1"), "UTF-8");
            }
            sleep(2000);
        } catch (IOException | InterruptedException | ParseException e) {
            e.printStackTrace();
        }
    }
}

 

简单JAVA爬虫

原文:http://www.cnblogs.com/colleen/p/4604618.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!