Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Document deriving the job directory from the spider name (#8035)

Adrianab27dfdb1f0f
diff --git a/docs/topics/jobs.rst b/docs/topics/jobs.rst
index c3043204b..30d57cba0 100644
--- a/docs/topics/jobs.rst
+++ b/docs/topics/jobs.rst
@@ -29,7 +29,7 @@ The job directory will store all required data to keep the state of a *single*
job (i.e. a spider run), so that if stopped cleanly, it can be resumed later.
.. warning:: This directory must *not* be shared by different spiders, or even
- different jobs of the same spider.
+ different jobs of the same spider. See :ref:`job-dir-spider-name`.
.. warning:: Treat the job directory with the same security care as your
Scrapy project source code. Do not point ``JOBDIR`` to a path that
@@ -49,6 +49,29 @@ a signal), and resume it later by issuing the same command::
scrapy crawl somespider -s JOBDIR=crawls/somespider-1
+.. _job-dir-spider-name:
+
+Deriving the job directory from the spider name
+===============================================
+
+One way to keep job directories apart is to build the path in
+:meth:`~scrapy.Spider.update_settings`, so that a group of spiders shares the
+same path except for the spider name:
+
+.. code-block:: python
+
+ from pathlib import Path
+
+ from scrapy import Spider
+
+
+ class BaseSpider(Spider):
+ @classmethod
+ def update_settings(cls, settings):
+ super().update_settings(settings)
+ settings.set("JOBDIR", str(Path("crawls", cls.name)), priority="spider")
+
+
.. _topics-keeping-persistent-state-between-batches:
Keeping persistent state between batches