1. 程式人生 > >Scrapy-自定制scrapy命令

Scrapy-自定制scrapy命令

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]

        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() crawlall.py
  • 在settings.py 中添加配置 COMMANDS_MODULE = ‘項目名稱.目錄名稱‘
  • 在項目目錄執行命令:scrapy crawlall

Scrapy-自定制scrapy命令