webmagic spider.java_爬虫框架Webmagic源码分析之Spider

本系列文章,针对Webmagic 0.6.1版本一个普通爬虫启动代码public static void main(String[] args) {Spider.create(new GithubRepoPageProcessor())从https:github.com/code4craft开始抓.addUrl("https://github.com/code4craft")//设置Schedul...
摘要由CSDN通过智能技术生成

本系列文章,针对Webmagic 0.6.1版本

一个普通爬虫启动代码

public static void main(String[] args) {

Spider.create(new GithubRepoPageProcessor())

从https:github.com/code4craft开始抓

.addUrl("https://github.com/code4craft")

//设置Scheduler,使用Redis来管理URL队列

.setScheduler(new RedisScheduler("localhost"))

//设置Pipeline,将结果以json方式保存到文件

.addPipeline(new JsonFilePipeline("D:\\data\\webmagic"))

//开启5个线程同时执行

.thread(5)

//启动爬虫

.run();

}

82c8dcefeabd8952f1632c911fd08a87.png

1、spider可配置插拔组件:

Downloader 提供自定义的Downloader,默认为HttpClientDownloader

Pipeline 提供自定义的Pipeline,可以配置多个,多个Pipeline链式处理结果。默认为ConsolePipeline

Scheduler 提供自定义的调度器,默认为QueueScheduler

PageProcessor 页面处理组件,开发者爬虫的实现

ExecutorService 可以用于提供自己实现的线程池来监控,默认为Fixed ExecutorService

SpiderListener 页面状态监听器,提供每个页面成功和错误的回调。可配置多个。

其中有:WebMagic四大组件:Pipeline,Scheduler,Downloader和PageProcesser 。这和Python中的Scrapy的理念是一致的。但是Scrapy还有一些中间件的概念,从结构图中便可以看出区别

0973df85a3899fafd19be7ca5c7e06e9.png

2、状态变量:

stat 0,初始化;1,运行中;2,已停止

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值