crawlab README

The project's README from github.com/crawlab-team/crawlab. As one markdown file: README.md.

Crawlab

中文 | English

Installation | Run | Screenshot | Architecture | Integration | Compare | Community & Sponsorship | CHANGELOG | Disclaimer

Golang-based distributed web crawler management platform, supporting various languages including Python, NodeJS, Go, Java, PHP and various web crawler frameworks including Scrapy, Puppeteer, Selenium.

Demo | Documentation

Installation

You can follow the installation guide.

Quick Start

Please open the command line prompt and execute the command below. Make sure you have installed docker-compose in advance.

git clone https://github.com/crawlab-team/examples
cd examples/docker/basic
docker-compose up -d

Next, you can look into the docker-compose.yml (with detailed config params) and the Documentation for further information.

Run

Docker

Please use docker-compose to one-click to start up. By doing so, you don't even have to configure MongoDB database. Create a file named docker-compose.yml and input the code below.

version: '3.3'
services:
  master: 
    image: crawlabteam/crawlab:latest
    container_name: crawlab_example_master
    environment:
      CRAWLAB_NODE_MASTER: "Y"
      CRAWLAB_MONGO_HOST: "mongo"
    volumes:
      - "./.crawlab/master:/root/.crawlab"
    ports:    
      - "8080:8080"
    depends_on:
      - mongo

  worker01: 
    image: crawlabteam/crawlab:latest
    container_name: crawlab_example_worker01
    environment:
      CRAWLAB_NODE_MASTER: "N"
      CRAWLAB_GRPC_ADDRESS: "master"
      CRAWLAB_FS_FILER_URL: "http://master:8080/api/filer"
    volumes:
      - "./.crawlab/worker01:/root/.crawlab"
    depends_on:
      - master

  worker02: 
    image: crawlabteam/crawlab:latest
    container_name: crawlab_example_worker02
    environment:
      CRAWLAB_NODE_MASTER: "N"
      CRAWLAB_GRPC_ADDRESS: "master"
      CRAWLAB_FS_FILER_URL: "http://master:8080/api/filer"
    volumes:
      - "./.crawlab/worker02:/root/.crawlab"
    depends_on:
      - master

  mongo:
    image: mongo:4.2
    container_name: crawlab_example_mongo
    restart: always

Then execute the command below, and Crawlab Master and Worker Nodes + MongoDB will start up. Open the browser and enter http://localhost:8080 to see the UI interface.

docker-compose up -d

For Docker Deployment details, please refer to relevant documentation.

Screenshot

Login

Home Page

Node List

Spider List

Spider Overview

Spider Files

Task Log

Task Results

Cron Job

Architecture

The architecture of Crawlab is consisted of a master node, worker nodes, SeaweedFS (a distributed file system) and MongoDB database.

The frontend app interacts with the master node, which communicates with other components such as MongoDB, SeaweedFS and worker nodes. Master node and worker nodes communicate with each other via gRPC (a RPC framework). Tasks are scheduled by the task scheduler module in the master node, and received by the task handler module in worker nodes, which executes these tasks in task runners. Task runners are actually processes running spider or crawler programs, and can also send data through gRPC (integrated in SDK) to other data sources, e.g. MongoDB.

Master Node

The Master Node is the core of the Crawlab architecture. It is the center control system of Crawlab.

The Master Node provides below services:

  1. Task Scheduling;
  2. Worker Node Management and Communication;
  3. Spider Deployment;
  4. Frontend and API Services;
  5. Task Execution (you can regard the Master Node as a Worker Node)

The Master Node communicates with the frontend app, and send crawling tasks to Worker Nodes. In the mean time, the Master Node uploads (deploys) spiders to the distributed file system SeaweedFS, for synchronization by worker nodes.

Worker Node

The main functionality of the Worker Nodes is to execute crawling tasks and store results and logs, and communicate with the Master Node through gRPC. By increasing the number of Worker Nodes, Crawlab can scale horizontally, and different crawling tasks can be assigned to different nodes to execute.

MongoDB

MongoDB is the operational database of Crawlab. It stores data of nodes, spiders, tasks, schedules, etc. Task queue is also stored in MongoDB.

SeaweedFS

SeaweedFS is an open source distributed file system authored by Chris Lu. It can robustly store and share files across a distributed system. In Crawlab, SeaweedFS mainly plays the role as file synchronization system and the place where task log files are stored.

Frontend

Frontend app is built upon Element-Plus, a popular Vue 3-based UI framework. It interacts with API hosted on the Master Node, and indirectly controls Worker Nodes.

Integration with Other Frameworks

Crawlab SDK provides some helper methods to make it easier for you to integrate your spiders into Crawlab, e.g. saving results.

Scrapy

In settings.py in your Scrapy project, find the variable named ITEM_PIPELINES (a dict variable). Add content below.

ITEM_PIPELINES = {
    'crawlab.scrapy.pipelines.CrawlabPipeline': 888,
}

Then, start the Scrapy spider. After it's done, you should be able to see scraped results in Task Detail -> Data

General Python Spider

Please add below content to your spider files to save results.

# import result saving method
from crawlab import save_item

# this is a result record, must be dict type
result = {'name': 'crawlab'}

# call result saving method
save_item(result)

Then, start the spider. After it's done, you should be able to see scraped results in Task Detail -> Data

Other Frameworks / Languages

A crawling task is actually executed through a shell command. The Task ID will be passed to the crawling task process in the form of environment variable named CRAWLAB_TASK_ID. By doing so, the data can be related to a task.

Comparison with Other Frameworks

There are existing spider management frameworks. So why use Crawlab?

The reason is that most of the existing platforms are depending on Scrapyd, which limits the choice only within python and scrapy. Surely scrapy is a great web crawl framework, but it cannot do everything.

Crawlab is easy to use, general enough to adapt spiders in any language and any framework. It has also a beautiful frontend interface for users to manage spiders much more easily.

Framework Technology Pros Cons Github Stats
Crawlab Golang + Vue Not limited to Scrapy, available for all programming languages and frameworks. Beautiful UI interface. Naturally support distributed spiders. Support spider management, task management, cron job, result export, analytics, notifications, configurable spiders, online code editor, etc. Not yet support spider versioning
ScrapydWeb Python Flask + Vue Beautiful UI interface, built-in Scrapy log parser, stats and graphs for task execution, support node management, cron job, mail notification, mobile. Full-feature spider management platform. Not support spiders other than Scrapy. Limited performance because of Python Flask backend.
Gerapy Python Django + Vue Gerapy is built by web crawler guru Germey Cui. Simple installation and deployment. Beautiful UI interface. Support node management, code edit, configurable crawl rules, etc. Again not support spiders other than Scrapy. A lot of bugs based on user feedback in v1.0. Look forward to improvement in v2.0
SpiderKeeper Python Flask Open-source Scrapyhub. Concise and simple UI interface. Support cron job. Perhaps too simplified, not support pagination, not support node management, not support spiders other than Scrapy.

Contributors

Supported by JetBrains

Community

If you feel Crawlab could benefit your daily work or your company, please add the author's Wechat account noting "Crawlab" to enter the discussion group.

crawlab (crawlab-team/crawlab)

Searching Database…

12.3K ·GitHub
这是什么东西?Crawlab 是一个开源的分布式爬虫管理平台:你可以上传用任何语言写的爬虫,在多台机器组成的集群上运行它们,并通过网页界面管理任务、定时调度和结果。
它是一个能接入我自己爬虫的库,还是一个独立的平台?一个独立自托管的平台:Master 节点、Worker 节点、MongoDB 和 SeaweedFS 都运行在你自己的服务器上。可选的 Crawlab SDK 只是一个辅助工具,用来在爬虫里保存结果。
怎么把它跑起来?创建一个包含 Crawlab 各服务的 docker-compose.yml,然后运行 'docker-compose up',Master 节点、Worker 节点和 MongoDB 会一起启动。接着在浏览器里打开网页界面即可。
开始之前需要先装好什么?只需要 docker-compose。这套 compose 配置自带 MongoDB,所以不用单独安装或配置数据库。
它还有什么做不到的吗?它自己的对比表里注明,目前还不支持爬虫版本管理。除此之外它的定位是功能齐全:支持定时任务(cron)、在线代码编辑器、通知、数据统计和结果导出。
这是给个人开发者用的,还是给要跑大量爬虫的团队用的?两者都适合,但它本身是为大规模场景设计的:爬虫分布在多个 Worker 节点上运行,面向任何日常工作或公司业务依赖爬取数据的人,不限语言和框架。
我的机器需要特定的操作系统吗?各节点以 Docker 容器方式运行,所以任何装了 Docker 的操作系统都可以,Linux 服务器是最常见的部署环境。管理界面是一个网页应用,任何浏览器都能使用。
我抓取的数据会离开我自己的服务器吗?不涉及任何外部服务:任务结果存到你自己的 MongoDB,任务日志文件存到 SeaweedFS,全部都在你自己的部署环境内。
我不是用 Scrapy 写的爬虫能跑吗——纯 Python、Node.js 或者别的呢?可以。爬取任务本质上就是一条 shell 命令,环境变量 CRAWLAB_TASK_ID 会把命令的输出关联到对应任务。Crawlab SDK 提供了保存结果的辅助方法,并为 Scrapy 和通用 Python 爬虫准备了现成的管道。
它是怎么实现在多台机器上运行爬虫的?Master 节点负责调度任务,并通过 gRPC 把任务分发给 Worker 节点;每个 Worker 在自己的任务运行器中执行任务。增加 Worker 就能横向扩展集群,SeaweedFS 则负责保持爬虫文件同步。
除了启动爬虫,网页界面还能做什么?管理爬虫和任务、设置 cron 定时任务、查看任务日志、在线编辑爬虫代码、配置爬虫、导出结果,以及查看数据统计和通知——官方截图展示了节点、爬虫和任务几个页面。
和 ScrapydWeb、Gerapy 相比,为什么选 Crawlab?那两个平台依赖 Scrapyd,所以只能管理 Scrapy 爬虫。Crawlab 能运行任何语言、任何框架的爬虫,原生支持分布式部署,还带有一个精致的 Vue 界面;代价是目前还不支持爬虫版本管理。
Size
24.8 MB
Stars
12.3K
Age
7y
Commits · 90 Days