How to Run Multiple Scrapy Spiders Efficiently: Cmdline, CrawlerProcess, and CrawlerRunner

This guide demonstrates how to write a Scrapy spider, run it via the command line, use CrawlerProcess and CrawlerRunner for single and multiple spider execution, and explains the observed middleware behavior to help you choose the most reliable method.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Run Multiple Scrapy Spiders Efficiently: Cmdline, CrawlerProcess, and CrawlerRunner

1. Run a spider from the command line

First, create the spider file baidu.py (see image). The spider can be launched in two ways: directly with scrapy crawl baidu or by executing the script with python baidu.py (see screenshot).

2. Run a spider inside a Python file

Three approaches are shown:

Cmdline method : use cmdline.execute to start the spider (image).

CrawlerProcess method : instantiate CrawlerProcess and call process.start() (image).

CrawlerRunner method : create a CrawlerRunner and schedule the spider (image).

3. Run multiple spiders in the same project

Add a second spider, e.g., sina.py, to the spiders directory (image).

Running both spiders with the cmdline method fails because the process exits after the first spider finishes (image).

Using CrawlerProcess allows both spiders to run concurrently; the middleware is initialized only once, and requests are sent in parallel (image).

Running spiders sequentially with CrawlerRunner also loads the middleware a single time but executes spiders one after another, reducing interference; this approach is recommended by the official documentation (image).

Summary

The cmdline.execute method offers the simplest configuration for running a single spider file repeatedly, while CrawlerProcess and CrawlerRunner provide more robust solutions for executing multiple spiders with minimal middleware duplication.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ScrapyWeb CrawlingCrawlerProcessCrawlerRunnerMultiple Spiders
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.