2017-02-19 5 views
5

再起動:どのように私は必要なものScrapyスパイダー

  • を行って

    1. スタートクローラー
    2. クローラージョブを、私はこれを試して再び

    1分

  • 開始クローラを待ちます
    from scrapy.crawler import CrawlerProcess 
    from scrapy.utils.project import get_project_settings 
    from time import sleep 
    
    while True: 
        process = CrawlerProcess(get_project_settings()) 
        process.crawl('spider_name') 
        process.start() 
        sleep(60) 
    

    しかし、エラーが表示されます。

    twisted.internet.error.ReactorNotRestartable

    を、私はそれを行う助けてください右

    のPython 3.6
    Scrapy 1.3.2
    Linuxの

  • +0

    http://stackoverflow.com/a/39955をご覧ください395/2572383 –

    答えて

    2

    私は解決策を見つけたと思う:

    from scrapy.utils.project import get_project_settings 
    from scrapy.crawler import CrawlerRunner 
    from twisted.internet import reactor 
    from twisted.internet import task 
    
    
    timeout = 60 
    
    
    def run_spider(): 
        l.stop() 
        runner = CrawlerRunner(get_project_settings()) 
        d = runner.crawl('spider_name') 
        d.addBoth(lambda _: l.start(timeout, False)) 
    
    
    l = task.LoopingCall(run_spider) 
    l.start(timeout) 
    
    reactor.run() 
    
    +0

    どうすればログを出力できますか? – Baks

    関連する問題