Scrapy用反应器在不同时间执行不同的爬行器

2024-06-02 15:50:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我想点击django网站上的一个按钮,我的蜘蛛应该开始抓取。我尝试爬虫程序,但因为我使用不同的蜘蛛。我决定使用CrawlerRunner。在第一次爬网之后,一切都很好,但是第二次爬网过程给了我这个错误

twisted.internet.error.ReactorNotRestartable

我尝试这个主题的解决方案: ReactorNotRestartable error in while loop with scrapy

所以我尝试以下代码的解决方案,但爬虫程序从未停止,它说ReactorAlreadyRunning

def test():
    configure_logging({'LOG_FORMAT': '%(levelname)s: %(message)s'})
    runner = CrawlerRunner(get_project_settings())
    d = runner.crawl(myspider.My_Spider)
    d.addBoth(lambda _: reactor.stop(stop_after_crawl=False))
    reactor.run()

它不会让我再爬一只蜘蛛。那么,如何在我的网站上的不同时间运行多个爬行器呢


Tags: django程序网站过程error解决方案按钮爬虫