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

java爬虫实例

时间:2021-01-06 11:55:59      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:image   截图   响应   col   code   content   cli   取数   rgs   

【实例简介】

【实例截图】 

技术图片

【核心代码】

package test;
 
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
 
public class CrawlerFirst {
    public static void main(String[] args) throws Exception {
        //打开浏览器
        CloseableHttpClient httpClient = HttpClients.createDefault();
 
        //输入网址
        HttpGet httpGet = new HttpGet("http://www.itcast.cn");
 
 
        //按回车发起请求
        CloseableHttpResponse response = httpClient.execute(httpGet);
        //解析响应 获取数据
 
        //判断状态码
        if(response.getStatusLine().getStatusCode() == 200){
            HttpEntity httpEntity = response.getEntity();
            String content = EntityUtils.toString(httpEntity,"utf-8");
 
            System.out.println(content);
        }
    }
}

 

--------------------------------------------------------------------------------------热爱编程,热爱生活!

java爬虫实例

标签:image   截图   响应   col   code   content   cli   取数   rgs   

原文地址:https://www.cnblogs.com/varchar-pig/p/14224551.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!