Running dozens of Scrapy spiders in a controlled manner

后端 未结 3 1742
北恋
北恋 2021-02-10 02:01

I\'m trying to build a system to run a few dozen Scrapy spiders, save the results to S3, and let me know when it finishes. There are several similar questions on StackOverflow (

3条回答
  •  自闭症患者
    2021-02-10 02:13

    The simplest way to do this is to run them all from the command line. For example:

    $ scrapy list | xargs -P 4 -n 1 scrapy crawl
    

    Will run all your spiders, with up to 4 running in parallel at any time. You can then send a notification in a script once this command has completed.

    A more robust option is to use scrapyd. This comes with an API, a minimal web interface, etc. It will also queue the crawls and only run a certain (configurable) number at once. You can interact with it via the API to start your spiders and send notifications once they are all complete.

    Scrapy Cloud is a perfect fit for this [disclaimer: I work for Scrapinghub]. It will allow you only to run a certain number at once and has a queue of pending jobs (which you can modify, browse online, prioritize, etc.) and a more complete API than scrapyd.

    You shouldn't run all your spiders in a single process. It will probably be slower, can introduce unforeseen bugs, and you may hit resource limits (like you did). If you run them separately using any of the options above, just run enough to max out your hardware resources (usually CPU/network). If you still get problems with file descriptors at that point you should increase the limit.

提交回复
热议问题