如何解决从循环内部运行爬虫蜘蛛
我有一个程序,它从 RabbitMQ 的队列 获取输入,然后运行一个传递此输入的爬虫蜘蛛。它工作正常,但只是第一次,在第一次输入后它会抛出这个错误:
twisted.internet.error.ReactorNotRestartable
这是我的代码:
def start_flow(crawler_class):
# Create the queue and all the connections
queue = Queue(connection_uri='amqp://guest:guest@localhost:5672/')
queue.create_connection()
queue.create_channel()
queue_name = _get_queue_name(crawler_class)
queue.define_queue(queue_name)
# ---------------------------------------
while True:
print("Waiting for the next input")
# Get an input
queue.consume(queue_name)
queue.channel.start_consuming()
input_ = queue.get_next_input()
# ------------
# Runs the crawler passing the input
runner = CrawlerRunner()
d = runner.crawl(crawler_class,input=input_)
d.addCallback(lambda _: reactor.stop())
reactor.run()
# ----------------------------
我已经尝试过 CrawlerProcess,但它抛出了同样的问题
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。