如何使用 Rabbitmq 或 Kafka 扩展以 user_id 作为输入并从数据库中获取相应 url 的 Scrapy 蜘蛛?

How to use Rabbitmq or Kafka to scale Scrapy spider which takes user_id as input and get respective urls from database?

我构建了 scrapy 蜘蛛,它将 user_id 作为命令行参数并从数据库中获取 url。现在我希望我的应用程序具有可扩展性。

与此同时,我正在查看互联网上提供的一些解决方案,但并不是所有的解决方案都完全符合我的要求,因为有些人建议将一堆 url 传递给 scrapy 并进行抓取,而其他人则建议使用root url 并将所有内容留给 Scrapy,但我的用例完全不同。我正在寻找这里的方法。

如果我可以跨蜘蛛程序分发客户端 ID,而不是分发 URL,那也很好。

您可以使用 Scrapinghub Cloud for that. Scrapy spiders work out-of-box on it, and you could use its Collection API 存储您的 user_id 供蜘蛛使用。

如果您想测试,可以使用免费套餐。

但如果您想尝试自托管解决方案,您可以尝试 Frontera

Frontera is a web crawling framework consisting of crawl frontier, and distribution/scaling primitives, allowing to build a large scale online web crawler.

Frontera takes care of the logic and policies to follow during the crawl. It stores and prioritizes links extracted by the crawler to decide which pages to visit next, and capable of doing it in a distributed manner.

Main features

  • (...)

  • Built-in Apache Kafka and ZeroMQ message buses.