1. 在項目文件夾中新建一個commands文件夾
2. 在command的文件夾中新建一個文件 crawlall.py
3.在crawlall.py 中寫一個command類,該類繼承 scrapy.commands
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