Locally run all of the spiders in Scrapy

后端 未结 4 1669
忘掉有多难
忘掉有多难 2020-12-03 03:27

Is there a way to run all of the spiders in a Scrapy project without using the Scrapy daemon? There used to be a way to run multiple spiders with scrapy crawl,

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 04:01

    this code is works on My scrapy version is 1.3.3 (save it in same directory in scrapy.cfg):

    from scrapy.utils.project import get_project_settings
    from scrapy.crawler import CrawlerProcess
    
    setting = get_project_settings()
    process = CrawlerProcess(setting)
    
    for spider_name in process.spiders.list():
        print ("Running spider %s" % (spider_name))
        process.crawl(spider_name,query="dvh") #query dvh is custom argument used in your scrapy
    
    process.start()
    

    for scrapy 1.5.x (so you don't get the deprecation warning)

    from scrapy.utils.project import get_project_settings
    from scrapy.crawler import CrawlerProcess
    
    setting = get_project_settings()
    process = CrawlerProcess(setting)
    
    for spider_name in process.spider_loader.list():
        print ("Running spider %s" % (spider_name))
        process.crawl(spider_name,query="dvh") #query dvh is custom argument used in your scrapy
    
    process.start()
    

提交回复
热议问题