码迷,mamicode.com
首页 > 编程语言 > 详细

简单JAVA爬虫

时间:2015-06-27 21:19:38      阅读:116      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!