0.3.28 • Published 7 months ago

espider v0.3.28

Weekly downloads
-
License
-
Repository
github
Last release
7 months ago

ESpider 爬虫框架

支持中间件, 布隆过滤重复请求, 断点续爬, 数据库队列, session状态保持

Feature

redis 分布式

安装

pnpm i espider 
pnpm i tslib 

前提条件

// tsconfig.json
{
  "compilerOptions": {
    "experimentalDecorators": true, // 启用装饰器
    "emitDecoratorMetadata": true   // 支持装饰器元数据 
  }
}

使用例子

使用 装饰器 进行事件绑定

export class TestSpider extends SessionESpider {
  public name = 'test'

  @SpiderReady()
  onReady() {
    console.log('onReady执行')
    this.addRequestTask({
      url: 'https://www.baidu.com?' + Date.now(),
    }, {
      skipCheck: true
    })
    // for (let i = 0; i < 30; i++) {
    //   this.addRequestTask({
    //     url: 'https://www.baidu.com?' + Date.now(),
    //   })
    // }
  }
  @SpiderRequestBefore()
  onTask(req: AddRequestTaskOptions){
    
  }
  
  @SpiderRequest() // 不传入 scope 则表示匹配所有请求
  request(request: AxiosSessionRequestConfig) {
    console.log('request', request.url)
    // console.log('request', request)
  }
  
  @SpiderResponse('www.baidu.com')
  responseFunc(
    res: AxiosSessionResponse, 
    req: AddRequestTaskOptions
  ) {
    console.log('response', req.url)
    // console.log('response', res.data)
  }

  @SpiderError(/baidu.com/)  // 支持正则
  onError(
    err: AxiosSessionError, 
    req: AddRequestTaskOptions
  ) {
    console.log(err.message)
    this.addRequestTask(req) // 请求重试
  }
}

const spider = new TestSpider()

spider.setOptions({
  requestConcurrency: 1,
  dupeFilterOptions: {
    alwaysResetCache: true,
  },
  requestInterval: 5000,
  taskOptions: {
    alwaysResetQueue: true,
  }
})
  .start()
  .then(() => console.log('启动成功'))

事件

查看 装饰器事件定义

0.3.28

7 months ago

0.3.26

7 months ago

0.3.9

1 year ago

0.3.16

1 year ago

0.3.15

1 year ago

0.3.13

1 year ago

0.3.12

1 year ago

0.3.11

1 year ago

0.3.10

1 year ago

0.3.20

1 year ago

0.3.25

1 year ago

0.3.23

1 year ago

0.3.22

1 year ago

0.3.21

1 year ago

0.3.0

1 year ago

0.3.19

1 year ago

0.3.18

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.8

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.3

1 year ago

0.2.0-beta

1 year ago

0.2.1-beta

1 year ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.2.6

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.5

1 year ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago