python爬虫--同时启动多个爬虫

scrapy同时启动多个爬虫

1.在项目里面创建一个commands文件夹
2.在创建好的commands文件夹中创建crawlall.py,并写入下面的内容

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()

3.开启多个爬虫命令
scrapy crawlall

posted @ 2020-01-12 11:41  corei5tj  阅读(81)  评论(0编辑  收藏  举报