Scrapy, a fast high-level web crawling & scraping framework for Python.
Document changing settings in Spider.from_crawler().
Andrey Rakhmatullina3f22046efaf
diff --git a/docs/topics/settings.rst b/docs/topics/settings.rstindex e1936eb5b..65823e071 100644--- a/docs/topics/settings.rst+++ b/docs/topics/settings.rst@@ -98,6 +98,26 @@ and settings set there should use the "spider" priority explicitly:super().update_settings(settings)settings.set("SOME_SETTING", "some value", priority="spider")+.. versionadded:: VERSION++It's also possible to modify the settings in the+:meth:`~scrapy.Spider.from_crawler` method, e.g. based on :ref:`spider+arguments <spiderargs>` or other logic:++.. code-block:: python++ import scrapy+++ class MySpider(scrapy.Spider):+ name = "myspider"++ @classmethod+ def from_crawler(cls, crawler, *args, **kwargs):+ spider = super().from_crawler(crawler, *args, **kwargs)+ spider.settings.set("SOME_SETTING", kwargs["value"], priority="spider")+ return spider+3. Project settings module--------------------------diff --git a/docs/topics/spiders.rst b/docs/topics/spiders.rstindex 5c3bf6e72..4ed9b8dc3 100644--- a/docs/topics/spiders.rst+++ b/docs/topics/spiders.rst@@ -136,6 +136,14 @@ scrapy.Spiderattributes in the new instance so they can be accessed later inside thespider's code.+ .. versionchanged:: VERSION++ The settings available in this method can now be modified, which is+ handy if you want to modify them based on arguments. As a+ consequence, the settings available in this method aren't the final+ values as they can be modified later by e.g. :ref:`add-ons+ <topics-addons>`.+:param crawler: crawler to which the spider will be bound:type crawler: :class:`~scrapy.crawler.Crawler` instance