zoukankan      html  css  js  c++  java
  • 爬虫入门程序开门见山

    建立一个maven项目,然后在pom.xml中加入依赖

    <dependencies>
        <!-- HttpClient -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.3</version>
        </dependency>
    
        <!-- 日志 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.25</version>
        </dependency>
    </dependencies>

    书写测试的代码如图

    public static void main(String[] args) throws Exception {
        CloseableHttpClient httpClient = HttpClients.createDefault();
    
        HttpGet httpGet = new HttpGet("http://www.baidu.cn/");
    
        CloseableHttpResponse response = httpClient.execute(httpGet);
    
        if (response.getStatusLine().getStatusCode() == 200) {
            String content = EntityUtils.toString(response.getEntity(), "UTF-8");
            System.out.println(content);
        }
    }
  • 相关阅读:
    Swift
    Swift
    Swift
    Swift
    Swift
    nineOldAnimation 应用
    Android 编程下 Touch 事件的分发和消费机制
    用Gradle 构建android程序
    CygWin模拟Linux环境进行Ant批量打包
    UML类图与类的关系详解
  • 原文地址:https://www.cnblogs.com/itboxue/p/10725669.html
Copyright © 2011-2022 走看看