二十六、Scrapy自定义命令
作者:互联网
-
创建命令目录及文件
-
settings.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() -
标签:二十六,自定义,process,self,list,爬虫,Scrapy,def,crawler 来源: https://www.cnblogs.com/nuochengze/p/13387925.html