mirror of https://github.com/scrapy/scrapy.git
Document changing settings in Spider.from_crawler().
This commit is contained in:
parent
77f39be407
commit
a3f22046ef
|
|
@ -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
|
||||
--------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -136,6 +136,14 @@ scrapy.Spider
|
|||
attributes in the new instance so they can be accessed later inside the
|
||||
spider'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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue