Scrapy-自定制scrapy命令
阿新 • • 發佈:2018-07-22
list ESS pyc div true man 配置 des rgs
- 在spiders同級創建任意目錄,如:commands
- 在其中創建 crawlall.py 文件 (此處文件名就是自定義的命令)
from scrapy.commands import ScrapyCommand from scrapy.utils.project import get_project_settings class Command(ScrapyCommand): requires_project = True def syntax(self): return ‘[options]‘ defshort_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() crawlall.py
- 在settings.py 中添加配置 COMMANDS_MODULE = ‘項目名稱.目錄名稱‘
- 在項目目錄執行命令:scrapy crawlall
Scrapy-自定制scrapy命令