Java爬虫

Java爬虫

Web Crawler, 网络爬虫

1. HttpClient

Java的 HTTP 协议客户端 HttpClient这个技术, 来实现抓取网页数据

1, GET请求

2, 带参数的GET请求

3, POST请求

4, 带参数的POST请求

5, 连接池

6, 请求参数

https://mvnrepository.com/

httpclient

https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.5.2

log4j

https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12/1.7.25

日志, 需要配置文件的, 所以 在 resources目录下, 新建一个 资源文件

2. Jsoup

1, 解析url

2, 解析字符串

3, 解析文件

4, 使用dom方式获取元素

5, 使用选择器获取元素

6, 使用组合选择器获取元素

2.1. 实例

1, 开发准备

2, 编写引导类, Service, Dao

3, 封装HttpClient

4, 实现爬虫功能1

5, 实现爬虫功能2

6, 实现爬虫功能3

配置参数, 配置请求信息

create table mall_item(
    id bigint(10) not null auto_increment comment '主键id',
    spu bigint(15) default null comment '商品集合id',
    sku bigint(15) default null comment '商品最小品类单元id',
    title varchar(100) default null comment '商品标题',
    price bigint(10) default null comment '商品价格',
    pic varchar(10) default null comment '商品图片',
    url varchar(200) default null comment '商品详情地址',
    created datetime default null comment '创建时间',
    updated datetime default null comment '更新时间',
    primary key(id),
    key sku (sku) using btree
) engine=InnoDB auto_increment=1 default charset=utf8 comment='商城商品表';

3. WebMagic

1, 搭建环境

2, 编写代码

3, 抽取元素

4, 获取链接

5, 使用Pipline保存数据

6, 爬虫的配置, 自动和终止

参考链接

https://www.bilibili.com/video/BV1V64y1s7p2

posted on 2021-10-08 21:23  beyondx  阅读(44)  评论(0编辑  收藏  举报

导航