一、背景环境
- 环境介绍
操作系统:Win10
Python版本:Python3.6
Scrapy版本:Scrapy1.5.1
二、多爬虫同时启动
首先在我们的项目里面创建一个commands文件夹用来存放我们等下需要开启多爬虫同时启动的文件
-
目录结构
- crawlall.py文件
from scrapy.commands import ScrapyCommand
class Command(ScrapyCommand):
requires_project = True
def syntax(self):
return '[options]'
def short_desc(self):
return 'Runs all of the spiders'
def run(self, args, opts):
spider_list = self.crawler_process.spiders.list()
for name in spider_list:
self.crawler_process.crawl(name, **opts.__dict__)
self.crawler_process.start()
- 命令行执行
scrapy crawlall