Scrapy同時啟動多個爬蟲


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM