Files
crawlab/README-zh.md
2019-07-29 20:30:39 +08:00

151 lines
5.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Crawlab
![](http://114.67.75.98:8081/buildStatus/icon?job=crawlab%2Fdevelop)
![](https://img.shields.io/badge/版本-v0.3.0-blue.svg)
<a href="https://github.com/tikazyq/crawlab/blob/master/LICENSE" target="_blank">
<img src="https://img.shields.io/badge/License-BSD-blue.svg">
</a>
中文 | [English](https://github.com/tikazyq/crawlab/blob/master/README.md)
基于Golang的分布式爬虫管理平台支持Python、NodeJS、Go、Java、PHP等多种编程语言以及多种爬虫框架。
[查看演示 Demo](http://114.67.75.98:8080) | [文档](https://tikazyq.github.io/crawlab-docs)
## 要求
- Go 1.12+
- Node.js 8.12+
- MongoDB 3.6+
- Redis
## 安装
三种方式:
1. [Docker](https://tikazyq.github.io/crawlab/Installation/Docker.md)(推荐)
2. [直接部署](https://tikazyq.github.io/crawlab/Installation/Direct.md)
3. [预览模式](https://tikazyq.github.io/crawlab/Installation/Direct.md)(快速体验)
## 截图
#### 首页
![](https://crawlab.oss-cn-hangzhou.aliyuncs.com/gitbook/home.png)
#### 爬虫列表
![](https://crawlab.oss-cn-hangzhou.aliyuncs.com/gitbook/spider-list.png)
#### 爬虫详情 - 概览
![](https://crawlab.oss-cn-hangzhou.aliyuncs.com/gitbook/spider-detail-overview.png)
#### 爬虫详情 - 分析
![](https://crawlab.oss-cn-hangzhou.aliyuncs.com/gitbook/spider-detail-analytics.png)
#### 任务详情 - 抓取结果
![](https://crawlab.oss-cn-hangzhou.aliyuncs.com/gitbook/task-detail-results.png)
#### 定时任务
![](https://crawlab.oss-cn-hangzhou.aliyuncs.com/gitbook/schedule-generate-cron.png)
## 架构
Crawlab的架构包括了一个主节点Master Node和多个工作节点Worker Node以及负责通信和数据储存的Redis和MongoDB数据库。
![](https://crawlab.oss-cn-hangzhou.aliyuncs.com/v0.3.0/architecture.png)
前端应用向主节点请求数据主节点通过MongoDB和Redis来执行任务派发调度以及部署工作节点收到任务之后开始执行爬虫任务并将任务结果储存到MongoDB。架构相对于`v0.3.0`之前的Celery版本有所精简去除了不必要的节点监控模块Flower节点监控主要由Redis完成。
### 主节点
主节点是整个Crawlab架构的核心属于Crawlab的中控系统。
主节点主要负责以下功能:
1. 爬虫任务调度
2. 工作节点管理和通信
3. 爬虫部署
4. 前端以及API服务
主节点负责与前端应用进行通信并通过Redis将爬虫任务派发给工作节点。同时主节点会同步部署爬虫给工作节点通过Redis和MongoDB的GridFS。
### 工作节点
工作节点的主要功能是执行爬虫任务和储存抓取数据与日志并且通过Redis的PubSub跟主节点通信。
### 爬虫 Spider
爬虫源代码或配置规则储存在`App`上,需要被部署到各个`worker`节点中。
### 任务 Task
任务被触发并被节点执行。用户可以在任务详情页面中看到任务到状态、日志和抓取结果。
### 前端 Frontend
前端是一个基于[Vue-Element-Admin](https://github.com/PanJiaChen/vue-element-admin)的单页应用。其中重用了很多Element-UI的控件来支持相应的展示。
### Flower
一个Celery的插件用于监控Celery节点。
## 与其他框架的集成
任务是利用python的`subprocess`模块中的`Popen`来实现的。任务ID将以环境变量`CRAWLAB_TASK_ID`的形式存在于爬虫任务运行的进程中,并以此来关联抓取数据。
在你的爬虫程序中,你需要将`CRAWLAB_TASK_ID`的值以`task_id`作为可以存入数据库中。这样Crawlab就知道如何将爬虫任务与抓取数据关联起来了。当前Crawlab只支持MongoDB。
### Scrapy
以下是Crawlab跟Scrapy集成的例子利用了Crawlab传过来的task_id和collection_name。
```python
import os
from pymongo import MongoClient
MONGO_HOST = '192.168.99.100'
MONGO_PORT = 27017
MONGO_DB = 'crawlab_test'
# scrapy example in the pipeline
class JuejinPipeline(object):
mongo = MongoClient(host=MONGO_HOST, port=MONGO_PORT)
db = mongo[MONGO_DB]
col_name = os.environ.get('CRAWLAB_COLLECTION')
if not col_name:
col_name = 'test'
col = db[col_name]
def process_item(self, item, spider):
item['task_id'] = os.environ.get('CRAWLAB_TASK_ID')
self.col.save(item)
return item
```
## 与其他框架比较
现在已经有一些爬虫管理框架了因此为啥还要用Crawlab
因为很多现有当平台都依赖于Scrapyd限制了爬虫的编程语言以及框架爬虫工程师只能用scrapy和python。当然scrapy是非常优秀的爬虫框架但是它不能做一切事情。
Crawlab使用起来很方便也很通用可以适用于几乎任何主流语言和框架。它还有一个精美的前端界面让用户可以方便的管理和运行爬虫。
|框架 | 类型 | 分布式 | 前端 | 依赖于Scrapyd |
|:---:|:---:|:---:|:---:|:---:|
| [Crawlab](https://github.com/tikazyq/crawlab) | 管理平台 | Y | Y | N
| [Gerapy](https://github.com/Gerapy/Gerapy) | 管理平台 | Y | Y | Y
| [SpiderKeeper](https://github.com/DormyMo/SpiderKeeper) | 管理平台 | Y | Y | Y
| [ScrapydWeb](https://github.com/my8100/scrapydweb) | 管理平台 | Y | Y | Y
| [Scrapyd](https://github.com/scrapy/scrapyd) | 网络服务 | Y | N | N/A
## 社区 & 赞助
如果您觉得Crawlab对您的日常开发或公司有帮助请加作者微信 tikazyq1 并注明"Crawlab",作者会将你拉入群。或者,您可以扫下方支付宝二维码给作者打赏去升级团队协作软件或买一杯咖啡。
<p align="center">
<img src="https://crawlab.oss-cn-hangzhou.aliyuncs.com/gitbook/qrcode.png" height="360">
<img src="https://crawlab.oss-cn-hangzhou.aliyuncs.com/gitbook/payment.jpg" height="360">
</p>