zoukankan      html  css  js  c++  java
  • java爬虫

    一、依赖包

    pom配置依赖包,主要有:

    其中主要用到框架:

    1. WebCollector

    WebCollector 是一个无须配置、便于二次开发的 JAVA 爬虫框架(内核),提供精简的的 API,只需少量代码即可实现一个功能强大的爬虫。

    源码中集成了 Jsoup,可进行精准的网页解析,2.x 版本中集成了 selenium,可以处理 JavaScript 生成的数据。

    教程:http://datahref.com/

    源码地址:https://github.com/CrawlScript/WebCollector

    2. Selenium-java

    Selenium是一个用于Web应用程序测试的工具; 
    后台代码模拟启动浏览器(这边用的是phantomjs ),访问页面等一些列操作。 

    Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。支持的浏览器包括IE(7, 8, 9, 10, 11),Mozilla Firefox,Safari,Google Chrome,Opera等。这个工具的主要功能包括:测试与浏览器的兼容性——测试你的应用程序看是否能够很好得工作在不同浏览器和操作系统之上。测试系统功能——创建回归测试检验软件功能和用户需求。支持自动录制动作和自动生成 .Net、Java、Perl等不同语言的测试脚本。

    https://www.cnblogs.com/Ming8006/p/5727542.html

    <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-batch</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <exclusions>  
                    <exclusion>  
                        <groupId>org.springframework.boot</groupId>  
                        <artifactId>spring-boot-starter-tomcat</artifactId>  
                    </exclusion>  
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jetty</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.batch</groupId>
                <artifactId>spring-batch-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>cn.edu.hfut.dmic.webcollector</groupId>
                <artifactId>WebCollector</artifactId>
                <version>2.71</version>
                <exclusions>
                    <exclusion>
                           <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>3.2.0</version>
            </dependency>
    
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.41</version>
            </dependency>
    
            <dependency>
                <groupId>commons-lang</groupId>
                <artifactId>commons-lang</artifactId>
                <version>2.6</version>
            </dependency>
        </dependencies>

    二、工具

    用到了phantomjs ,是一个基于 WebKit 的“无头浏览器”环境。对“无头”,你可以理解成没有一个前端的 GUI 界面,所有的东西都在后台运行。一个纯后台的,完整功能的浏览器。

    有windows版本,也有linux版本。自行下载即可。

    好了,万事俱备,接下来只需要编写爬取逻辑就行啦。

  • 相关阅读:
    让我用69406条评论告诉你“反贪风暴”好不好看!!!
    【大数据】爬取全部的校园新闻
    【大数据】获取一篇新闻的全部信息
    【大数据】理解爬虫原理
    中文统计
    [大数据]统计词频
    数据库表设计以及表字段命名
    设计模式的理论理解
    文件上传之oss服务器上传文件简笔
    QueryWrapper/UpdateWrapper认识
  • 原文地址:https://www.cnblogs.com/qcxdoit/p/10368402.html
Copyright © 2011-2022 走看看