zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    hdu1042-N!-(java大数)
    拓扑排序-有向无环图(DAG, Directed Acyclic Graph)
    deleted
    deleted
    deleted
    deleted
    deleted
    deleted
    deleted
    deleted
  • 原文地址:https://www.cnblogs.com/knighterrant/p/10812430.html
Copyright © 2011-2022 走看看