9.1 KiB
Core API
System Message: ERROR/3 (<stdin>, line 7)
Unknown directive type "versionadded".
.. versionadded:: 0.15
This section documents the Scrapy core API, and it's intended for developers of extensions and middlewares.
Crawler API
The main entry point to Scrapy API is the :class:`~scrapy.crawler.Crawler` object, passed to extensions through the from_crawler class method. This object provides access to all Scrapy core components, and it's the only way for extensions to access them and hook their functionality into Scrapy.
System Message: ERROR/3 (<stdin>, line 17); backlink
Unknown interpreted text role "class".System Message: ERROR/3 (<stdin>, line 22)
Unknown directive type "module".
.. module:: scrapy.crawler :synopsis: The Scrapy crawler
The Extension Manager is responsible for loading and keeping track of installed extensions and it's configured through the :setting:`EXTENSIONS` setting which contains a dictionary of all available extensions and their order similar to how you :ref:`configure the downloader middlewares <topics-downloader-middleware-setting>`.
System Message: ERROR/3 (<stdin>, line 25); backlink
Unknown interpreted text role "setting".System Message: ERROR/3 (<stdin>, line 25); backlink
Unknown interpreted text role "ref".The Crawler object must be instantiated with a :class:`scrapy.settings.Settings` object.
System Message: ERROR/3 (<stdin>, line 33); backlink
Unknown interpreted text role "class".System Message: ERROR/3 (<stdin>, line 36)
Unknown directive type "attribute".
.. attribute:: settings
The settings manager of this crawler.
This is used by extensions & middlewares to access the Scrapy settings
of this crawler.
For an introduction on Scrapy settings see :ref:`topics-settings`.
For the API see :class:`~scrapy.settings.Settings` class.
System Message: ERROR/3 (<stdin>, line 47)
Unknown directive type "attribute".
.. attribute:: signals
The signals manager of this crawler.
This is used by extensions & middlewares to hook themselves into Scrapy
functionality.
For an introduction on signals see :ref:`topics-signals`.
For the API see :class:`~scrapy.signalmanager.SignalManager` class.
System Message: ERROR/3 (<stdin>, line 58)
Unknown directive type "attribute".
.. attribute:: stats
The stats collector of this crawler.
This is used from extensions & middlewares to record stats of their
behaviour, or access stats collected by other extensions.
For an introduction on stats collection see :ref:`topics-stats`.
For the API see :class:`~scrapy.statscol.StatsCollector` class.
System Message: ERROR/3 (<stdin>, line 69)
Unknown directive type "attribute".
.. attribute:: extensions
The extension manager that keeps track of enabled extensions.
Most extensions won't need to access this attribute.
For an introduction on extensions and a list of available extensions on
Scrapy see :ref:`topics-extensions`.
System Message: ERROR/3 (<stdin>, line 78)
Unknown directive type "attribute".
.. attribute:: spiders
The spider manager which takes care of loading and instantiating
spiders.
Most extensions won't need to access this attribute.
System Message: ERROR/3 (<stdin>, line 85)
Unknown directive type "attribute".
.. attribute:: engine
The execution engine, which coordinates the core crawling logic
between the scheduler, downloader and spiders.
Some extension may want to access the Scrapy engine, to modify inspect
or modify the downloader and scheduler behaviour, although this is an
advanced use and this API is not yet stable.
System Message: ERROR/3 (<stdin>, line 94)
Unknown directive type "method".
.. method:: configure()
Configure the crawler.
This loads extensions, middlewares and spiders, leaving the crawler
ready to be started. It also configures the execution engine.
System Message: ERROR/3 (<stdin>, line 101)
Unknown directive type "method".
.. method:: start()
Start the crawler. This calss :meth:`configure` if it hasn't been called yet.
Settings API
System Message: ERROR/3 (<stdin>, line 108)
Unknown directive type "module".
.. module:: scrapy.settings :synopsis: Settings manager
This object that provides access to Scrapy settings.
System Message: ERROR/3 (<stdin>, line 115)
Unknown directive type "attribute".
.. attribute:: overrides Global overrides are the ones that take most precedence, and are usually populated by command-line options. Overrides should be populated *before* configuring the Crawler object (through the :meth:`~scrapy.crawler.Crawler.configure` method), otherwise they won't have any effect. You don't typically need to worry about overrides unless you are implementing your own Scrapy command.
System Message: ERROR/3 (<stdin>, line 125)
Unknown directive type "method".
.. method:: get(name, default=None) Get a setting value without affecting its original type. :param name: the setting name :type name: string :param default: the value to return if no setting is found :type default: any
System Message: ERROR/3 (<stdin>, line 135)
Unknown directive type "method".
.. method:: getbool(name, default=False) Get a setting value as a boolean. For example, both ``1`` and ``'1'``, and ``True`` return ``True``, while ``0``, ``'0'``, ``False`` and ``None`` return ``False```` For example, settings populated through environment variables set to ``'0'`` will return ``False`` when using this method. :param name: the setting name :type name: string :param default: the value to return if no setting is found :type default: any
System Message: ERROR/3 (<stdin>, line 150)
Unknown directive type "method".
.. method:: getint(name, default=0) Get a setting value as an int :param name: the setting name :type name: string :param default: the value to return if no setting is found :type default: any
System Message: ERROR/3 (<stdin>, line 160)
Unknown directive type "method".
.. method:: getfloat(name, default=0.0) Get a setting value as a float :param name: the setting name :type name: string :param default: the value to return if no setting is found :type default: any
System Message: ERROR/3 (<stdin>, line 170)
Unknown directive type "method".
.. method:: getlist(name, default=None) Get a setting value as a list. If the setting original type is a list it will be returned verbatim. If it's a string it will be split by ",". For example, settings populated through environment variables set to ``'one,two'`` will return a list ['one', 'two'] when using this method. :param name: the setting name :type name: string :param default: the value to return if no setting is found :type default: any
Signals API
System Message: ERROR/3 (<stdin>, line 189)
Unknown directive type "module".
.. module:: scrapy.signalmanager :synopsis: The signal manager
System Message: ERROR/3 (<stdin>, line 194)
Unknown directive type "method".
.. method:: connect(receiver, signal)
Connect a receiver function to a signal.
The signal can be any object, although Scrapy comes with some
predefined signals that are documented in the :ref:`topics-signals`
section.
:param receiver: the function to be connected
:type receiver: callable
:param signal: the signal to connect to
:type signal: object
System Message: ERROR/3 (<stdin>, line 208)
Unknown directive type "method".
.. method:: send_catch_log(signal, \*\*kwargs)
Send a signal, catch exceptions and log them.
The keyword arguments are passed to the signal handlers (connected
through the :meth:`connect` method).
System Message: ERROR/3 (<stdin>, line 215)
Unknown directive type "method".
.. method:: send_catch_log_deferred(signal, \*\*kwargs)
Like :meth:`send_catch_log` but supports returning `deferreds`_ from
signal handlers.
Returns a `deferred`_ that gets fired once all signal handlers
deferreds were fired. Send a signal, catch exceptions and log them.
The keyword arguments are passed to the signal handlers (connected
through the :meth:`connect` method).
System Message: ERROR/3 (<stdin>, line 226)
Unknown directive type "method".
.. method:: disconnect(receiver, signal)
Disconnect a receiver function from a signal. This has the opposite
effect of the :meth:`connect` method, and the arguments are the same.
System Message: ERROR/3 (<stdin>, line 231)
Unknown directive type "method".
.. method:: disconnect_all(signal)
Disconnect all receivers from the given signal.
:param signal: the signal to disconnect from
:type signal: object
Stats Collector API
There are several Stats Collectors available under the :mod:`scrapy.statscol` module and they all implement the Stats Collector API defined by the :class:`~scrapy.statscol.StatsCollector` class (which they all inherit from).
System Message: ERROR/3 (<stdin>, line 243); backlink
Unknown interpreted text role "mod".System Message: ERROR/3 (<stdin>, line 243); backlink
Unknown interpreted text role "class".System Message: ERROR/3 (<stdin>, line 248)
Unknown directive type "module".
.. module:: scrapy.statscol :synopsis: Stats Collectors
System Message: ERROR/3 (<stdin>, line 253)
Unknown directive type "method".
.. method:: get_value(key, default=None)
Return the value for the given stats key or default if it doesn't exist.
System Message: ERROR/3 (<stdin>, line 257)
Unknown directive type "method".
.. method:: get_stats()
Get all stats from the currently running spider as a dict.
System Message: ERROR/3 (<stdin>, line 261)
Unknown directive type "method".
.. method:: set_value(key, value)
Set the given value for the given stats key.
System Message: ERROR/3 (<stdin>, line 265)
Unknown directive type "method".
.. method:: set_stats(stats)
Override the current stats with the dict passed in ``stats`` argument.
System Message: ERROR/3 (<stdin>, line 269)
Unknown directive type "method".
.. method:: inc_value(key, count=1, start=0)
Increment the value of the given stats key, by the given count,
assuming the start value given (when it's not set).
System Message: ERROR/3 (<stdin>, line 274)
Unknown directive type "method".
.. method:: max_value(key, value)
Set the given value for the given key only if current value for the
same key is lower than value. If there is no current value for the
given key, the value is always set.
System Message: ERROR/3 (<stdin>, line 280)
Unknown directive type "method".
.. method:: min_value(key, value)
Set the given value for the given key only if current value for the
same key is greater than value. If there is no current value for the
given key, the value is always set.
System Message: ERROR/3 (<stdin>, line 286)
Unknown directive type "method".
.. method:: clear_stats()
Clear all stats.
The following methods are not part of the stats collection api but instead used when implementing custom stats collectors:
System Message: ERROR/3 (<stdin>, line 293)
Unknown directive type "method".
.. method:: open_spider(spider)
Open the given spider for stats collection.
System Message: ERROR/3 (<stdin>, line 297)
Unknown directive type "method".
.. method:: close_spider(spider)
Close the given spider. After this is called, no more specific stats
can be accessed or collected.