Scrapy, a fast high-level web crawling & scraping framework for Python.
[docs] update redirect links to python3
Adityaf37b1bdc5616
diff --git a/docs/intro/tutorial.rst b/docs/intro/tutorial.rstindex 1768badbb..ab6fd4829 100644--- a/docs/intro/tutorial.rst+++ b/docs/intro/tutorial.rst@@ -25,16 +25,16 @@ Scrapy.If you're already familiar with other languages, and want to learn Python quickly, the `Python Tutorial`_ is a good resource.If you're new to programming and want to start with Python, the following books-may be useful to you:+may be useful to you:* `Automate the Boring Stuff With Python`_-* `How To Think Like a Computer Scientist`_+* `How To Think Like a Computer Scientist`_-* `Learn Python 3 The Hard Way`_+* `Learn Python 3 The Hard Way`_You can also take a look at `this list of Python resources for non-programmers`_,-as well as the `suggested resources in the learnpython-subreddit`_.+as well as the `suggested resources in the learnpython-subreddit`_... _Python: https://www.python.org/.. _this list of Python resources for non-programmers: https://wiki.python.org/moin/BeginnersGuide/NonProgrammers@@ -62,7 +62,7 @@ This will create a ``tutorial`` directory with the following contents::__init__.pyitems.py # project items definition file-+middlewares.py # project middlewares filepipelines.py # project pipelines filediff --git a/docs/topics/contracts.rst b/docs/topics/contracts.rstindex 43db8f101..319f577bc 100644--- a/docs/topics/contracts.rst+++ b/docs/topics/contracts.rst@@ -136,7 +136,7 @@ Detecting check runs====================When ``scrapy check`` is running, the ``SCRAPY_CHECK`` environment variable is-set to the ``true`` string. You can use `os.environ`_ to perform any change to+set to the ``true`` string. You can use :data:`os.environ` to perform any change toyour spiders or your settings when ``scrapy check`` is used::import os@@ -148,5 +148,3 @@ your spiders or your settings when ``scrapy check`` is used::def __init__(self):if os.environ.get('SCRAPY_CHECK'):pass # Do some scraper adjustments when a check is running--.. _os.environ: https://docs.python.org/3/library/os.html#os.environdiff --git a/docs/topics/downloader-middleware.rst b/docs/topics/downloader-middleware.rstindex 61a3806fb..d7ec53bfa 100644--- a/docs/topics/downloader-middleware.rst+++ b/docs/topics/downloader-middleware.rst@@ -739,7 +739,7 @@ HttpProxyMiddlewareThis middleware sets the HTTP proxy to use for requests, by setting the``proxy`` meta value for :class:`~scrapy.http.Request` objects.- Like the Python standard library module `urllib.request`_, it obeys+ Like the Python standard library module :mod:`urllib.request`, it obeysthe following environment variables:* ``http_proxy``@@ -751,8 +751,6 @@ HttpProxyMiddlewareKeep in mind this value will take precedence over ``http_proxy``/``https_proxy``environment variables, and it will also ignore ``no_proxy`` environment variable.-.. _urllib.request: https://docs.python.org/3/library/urllib.request.html-RedirectMiddleware------------------@@ -982,7 +980,7 @@ RobotsTxtMiddlewareScrapy ships with support for the following robots.txt_ parsers:* :ref:`Protego <protego-parser>` (default)- * :ref:`RobotFileParser <python-robotfileparser>`+ * :class:`~urllib.robotparser.RobotFileParser`* :ref:`Reppy <reppy-parser>`* :ref:`Robotexclusionrulesparser <rerp-parser>`@@ -1030,13 +1028,10 @@ Based on `Protego <https://github.com/scrapy/protego>`_:Scrapy uses this parser by default.-.. _python-robotfileparser:-RobotFileParser~~~~~~~~~~~~~~~-Based on `RobotFileParser-<https://docs.python.org/3.7/library/urllib.robotparser.html>`_:+Based on :class:`~urllib.robotparser.RobotFileParser`:* is Python's built-in robots.txt_ parserdiff --git a/docs/topics/dynamic-content.rst b/docs/topics/dynamic-content.rstindex b98133676..22bcac268 100644--- a/docs/topics/dynamic-content.rst+++ b/docs/topics/dynamic-content.rst@@ -115,7 +115,7 @@ data from it depends on the type of response:- If the response is HTML or XML, use :ref:`selectors<topics-selectors>` as usual.-- If the response is JSON, use `json.loads`_ to load the desired data from+- If the response is JSON, use :func:`json.loads` to load the desired data from:attr:`response.text <scrapy.http.TextResponse.text>`::data = json.loads(response.text)@@ -130,7 +130,7 @@ data from it depends on the type of response:- If the response is JavaScript, or HTML with a ``<script/>`` elementcontaining the desired data, see :ref:`topics-parsing-javascript`.-- If the response is CSS, use a `regular expression`_ to extract the desired+- If the response is CSS, use :mod:`re` to extract the desireddata from :attr:`response.text <scrapy.http.TextResponse.text>`... _topics-parsing-images:@@ -168,8 +168,8 @@ JavaScript code:Once you have a string with the JavaScript code, you can extract the desireddata from it:-- You might be able to use a `regular expression`_ to extract the desired- data in JSON format, which you can then parse with `json.loads`_.+- You might be able to use :mod:`re` to extract the desired+ data in JSON format, which you can then parse with :func:`json.loads`.For example, if the JavaScript code contains a separate line like``var data = {"field": "value"};`` you can extract that data as follows:@@ -241,9 +241,7 @@ along with `scrapy-selenium`_ for seamless integration... _headless browser: https://en.wikipedia.org/wiki/Headless_browser.. _JavaScript: https://en.wikipedia.org/wiki/JavaScript.. _js2xml: https://github.com/scrapinghub/js2xml-.. _json.loads: https://docs.python.org/3/library/json.html#json.loads.. _pytesseract: https://github.com/madmaze/pytesseract-.. _regular expression: https://docs.python.org/3/library/re.html.. _scrapy-selenium: https://github.com/clemfromspace/scrapy-selenium.. _scrapy-splash: https://github.com/scrapy-plugins/scrapy-splash.. _Selenium: https://www.selenium.dev/diff --git a/docs/topics/email.rst b/docs/topics/email.rstindex aed3deb2e..e347c3a35 100644--- a/docs/topics/email.rst+++ b/docs/topics/email.rst@@ -7,7 +7,7 @@ Sending e-mail.. module:: scrapy.mail:synopsis: Email sending facility-Although Python makes sending e-mails relatively easy via the `smtplib`_+Although Python makes sending e-mails relatively easy via the :mod:`smtplib`library, Scrapy provides its own facility for sending e-mails which is veryeasy to use and it's implemented using :doc:`Twisted non-blocking IO<twisted:core/howto/defer-intro>`, to avoid interfering with the non-blocking@@ -15,8 +15,6 @@ IO of the crawler. It also provides a simple API for sending attachments andit's very easy to configure, with a few :ref:`settings<topics-email-settings>`.-.. _smtplib: https://docs.python.org/3/library/smtplib.html-Quick example=============diff --git a/docs/topics/exporters.rst b/docs/topics/exporters.rstindex 4ba8714bd..f73c6728d 100644--- a/docs/topics/exporters.rst+++ b/docs/topics/exporters.rst@@ -311,7 +311,7 @@ CsvItemExporterThe additional keyword arguments of this ``__init__`` method are passed to the:class:`BaseItemExporter` ``__init__`` method, and the leftover arguments to the- `csv.writer`_ ``__init__`` method, so you can use any ``csv.writer`` ``__init__`` method+ :func:`csv.writer` ``__init__`` method, so you can use any ``csv.writer`` ``__init__`` methodargument to customize this exporter.A typical output of this exporter would be::@@ -320,8 +320,6 @@ CsvItemExporterColor TV,1200DVD player,200-.. _csv.writer: https://docs.python.org/3/library/csv.html#csv.writer-PickleItemExporter------------------@@ -335,15 +333,13 @@ PickleItemExporter:param protocol: The pickle protocol to use.:type protocol: int- For more information, refer to the `pickle module documentation`_.+ For more information, refer :mod:`pickle`.The additional keyword arguments of this ``__init__`` method are passed to the:class:`BaseItemExporter` ``__init__`` method.Pickle isn't a human readable format, so no output examples are provided.-.. _pickle module documentation: https://docs.python.org/3/library/pickle.html-PprintItemExporter------------------@@ -372,8 +368,8 @@ JsonItemExporterExports Items in JSON format to the specified file-like object, writing allobjects as a list of objects. The additional ``__init__`` method arguments arepassed to the :class:`BaseItemExporter` ``__init__`` method, and the leftover- arguments to the `JSONEncoder`_ ``__init__`` method, so you can use any- `JSONEncoder`_ ``__init__`` method argument to customize this exporter.+ arguments to the :class:`~json.JSONEncoder` ``__init__`` method, so you can use any+ :class:`~json.JSONEncoder` ``__init__`` method argument to customize this exporter.:param file: the file-like object to use for exporting the data. Its ``write`` method shouldaccept ``bytes`` (a disk file opened in binary mode, a ``io.BytesIO`` object, etc)@@ -393,8 +389,6 @@ JsonItemExporterstream-friendly format, consider using :class:`JsonLinesItemExporter`instead, or splitting the output in multiple chunks.-.. _JSONEncoder: https://docs.python.org/3/library/json.html#json.JSONEncoder-JsonLinesItemExporter---------------------@@ -403,8 +397,8 @@ JsonLinesItemExporterExports Items in JSON format to the specified file-like object, writing oneJSON-encoded item per line. The additional ``__init__`` method arguments are passedto the :class:`BaseItemExporter` ``__init__`` method, and the leftover arguments to- the `JSONEncoder`_ ``__init__`` method, so you can use any `JSONEncoder`_- ``__init__`` method argument to customize this exporter.+ the :class:`~json.JSONEncoder` ``__init__`` method, so you can use any+ :class:`~json.JSONEncoder` ``__init__`` method argument to customize this exporter.:param file: the file-like object to use for exporting the data. Its ``write`` method shouldaccept ``bytes`` (a disk file opened in binary mode, a ``io.BytesIO`` object, etc)@@ -417,8 +411,6 @@ JsonLinesItemExporterUnlike the one produced by :class:`JsonItemExporter`, the format produced bythis exporter is well suited for serializing large amounts of data.-.. _JSONEncoder: https://docs.python.org/3/library/json.html#json.JSONEncoder-MarshalItemExporter-------------------diff --git a/docs/topics/extensions.rst b/docs/topics/extensions.rstindex f57e37e6f..1b8413abf 100644--- a/docs/topics/extensions.rst+++ b/docs/topics/extensions.rst@@ -364,7 +364,7 @@ Debugger extension.. class:: Debugger-Invokes a `Python debugger`_ inside a running Scrapy process when a `SIGUSR2`_+Invokes a :mod:`Python debugger <pdb>`: inside a running Scrapy process when a `SIGUSR2`_signal is received. After the debugger is exited, the Scrapy process continuesrunning normally.@@ -372,5 +372,4 @@ For more info see `Debugging in Python`_.This extension only works on POSIX-compliant platforms (i.e. not Windows).-.. _Python debugger: https://docs.python.org/3/library/pdb.html.. _Debugging in Python: https://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/diff --git a/docs/topics/items.rst b/docs/topics/items.rstindex 36731571e..2e5c88054 100644--- a/docs/topics/items.rst+++ b/docs/topics/items.rst@@ -15,7 +15,7 @@ especially in a larger project with many spiders.To define common output data format Scrapy provides the :class:`Item` class.:class:`Item` objects are simple containers used to collect the scraped data.-They provide a `dictionary-like`_ API with a convenient syntax for declaring+They provide a :class:`dict` like API with a convenient syntax for declaringtheir available fields.Various Scrapy components use extra information provided by Items:@@ -24,8 +24,6 @@ serialization can be customized using Item fields metadata, :mod:`trackref`tracks Item instances to help find memory leaks(see :ref:`topics-leaks-trackrefs`), etc.-.. _dictionary-like: https://docs.python.org/3/library/stdtypes.html#dict-.. _topics-items-declaring:Declaring Items@@ -79,7 +77,7 @@ Working with ItemsHere are some examples of common tasks performed with items, using the``Product`` item :ref:`declared above <topics-items-declaring>`. You will-notice the API is very similar to the `dict API`_.+notice the API is very similar to the :class:`dict` API.Creating items--------------@@ -145,7 +143,7 @@ KeyError: 'Product does not support field: lala'Accessing all populated values-------------------------------To access all populated values, just use the typical `dict API`_:+To access all populated values, just use the typical :class:`dict`:>>> product.keys()['price', 'name']@@ -175,9 +173,7 @@ other item as well.If that is not the desired behavior, use a deep copy instead.-See the `documentation of the copy module`_ for more information.--.. _documentation of the copy module: https://docs.python.org/3/library/copy.html+See :mod:`copy` for more information.To create a shallow copy of an item, you can either call:meth:`~scrapy.item.Item.copy` on an existing item@@ -235,7 +231,7 @@ Item objectsReturn a new Item optionally initialized from the given argument.- Items replicate the standard `dict API`_, including its ``__init__`` method, and+ Items replicate the standard :class:`dict`, including its ``__init__`` method, andalso provide the following additional API members:.. automethod:: copy@@ -249,22 +245,17 @@ Item objects:class:`Field` objects used in the :ref:`Item declaration<topics-items-declaring>`.-.. _dict API: https://docs.python.org/3/library/stdtypes.html#dict-Field objects=============.. class:: Field([arg])- The :class:`Field` class is just an alias to the built-in `dict`_ class and+ The :class:`Field` class is just an alias to the built-in :class:`dict` class anddoesn't provide any extra functionality or attributes. In other words,:class:`Field` objects are plain-old Python dicts. A separate class is usedto support the :ref:`item declaration syntax <topics-items-declaring>`based on class attributes.-.. _dict: https://docs.python.org/3/library/stdtypes.html#dict--Other classes related to Item=============================diff --git a/docs/topics/logging.rst b/docs/topics/logging.rstindex a85e1a769..df631b3dc 100644--- a/docs/topics/logging.rst+++ b/docs/topics/logging.rst@@ -9,8 +9,7 @@ Loggingexplicit calls to the Python standard logging. Keep reading to learn moreabout the new logging system.-Scrapy uses `Python's builtin logging system-<https://docs.python.org/3/library/logging.html>`_ for event logging. We'll+Scrapy uses :mod:`logging` for event logging. We'llprovide some simple examples to get you started, but for more advanceduse-cases it's strongly suggested to read thoroughly its documentation.@@ -86,7 +85,7 @@ path::Module logging, `HowTo <https://docs.python.org/3/howto/logging.html>`_Basic Logging Tutorial- Module logging, `Loggers <https://docs.python.org/3/library/logging.html#logger-objects>`_+ Module logging, :class:`~logging.Logger`Further documentation on loggers.. _topics-logging-from-spiders:@@ -190,7 +189,7 @@ to override some of the Scrapy settings regarding logging... seealso::- Module `logging.handlers <https://docs.python.org/3/library/logging.handlers.html>`_+ Module :mod:`logging.handlers`Further documentation on available handlers.. _custom-log-formats:@@ -256,10 +255,10 @@ scrapy.utils.log moduleIn that case, its usage is not required but it's recommended.Another option when running custom scripts is to manually configure the logging.- To do this you can use `logging.basicConfig()`_ to set a basic root handler.+ To do this you can use :func:`logging.basicConfig` to set a basic root handler.Note that :class:`~scrapy.crawler.CrawlerProcess` automatically calls ``configure_logging``,- so it is recommended to only use `logging.basicConfig()`_ together with+ so it is recommended to only use :func:`logging.basicConfig` together with:class:`~scrapy.crawler.CrawlerRunner`.This is an example on how to redirect ``INFO`` or higher messages to a file::@@ -275,7 +274,3 @@ scrapy.utils.log moduleRefer to :ref:`run-from-script` for more details about using Scrapy thisway.--.. _logging.basicConfig(): https://docs.python.org/3/library/logging.html#logging.basicConfig--diff --git a/docs/topics/request-response.rst b/docs/topics/request-response.rstindex 6c5a08409..7260141e9 100644--- a/docs/topics/request-response.rst+++ b/docs/topics/request-response.rst@@ -566,12 +566,10 @@ dealing with JSON requests.set to ``'POST'`` automatically.:type data: JSON serializable object- :param dumps_kwargs: Parameters that will be passed to underlying `json.dumps`_ method which is used to serialize+ :param dumps_kwargs: Parameters that will be passed to underlying :func:`json.dumps` method which is used to serializedata into JSON format.:type dumps_kwargs: dict-.. _json.dumps: https://docs.python.org/3/library/json.html#json.dumps-JsonRequest usage example-------------------------@@ -724,7 +722,7 @@ Response objectsConstructs an absolute url by combining the Response's :attr:`url` witha possible relative url.- This is a wrapper over `urllib.parse.urljoin`_, it's merely an alias for+ This is a wrapper over :func:`~urllib.parse.urljoin`, it's merely an alias formaking this call::urllib.parse.urljoin(response.url, url)@@ -734,8 +732,6 @@ Response objects.. automethod:: Response.follow_all-.. _urllib.parse.urljoin: https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urljoin-.. _topics-request-response-ref-response-subclasses:Response subclassesdiff --git a/docs/topics/selectors.rst b/docs/topics/selectors.rstindex 0f90b28c0..bb46ea80f 100644--- a/docs/topics/selectors.rst+++ b/docs/topics/selectors.rst@@ -14,7 +14,7 @@ achieve this, such as:drawback: it's slow.* `lxml`_ is an XML parsing library (which also parses HTML) with a pythonic- API based on `ElementTree`_. (lxml is not part of the Python standard+ API based on :mod:`~xml.etree.ElementTree`. (lxml is not part of the Python standardlibrary.)Scrapy comes with its own mechanism for extracting data. They're called@@ -36,7 +36,6 @@ defines selectors to associate those styles with specific HTML elements... _BeautifulSoup: https://www.crummy.com/software/BeautifulSoup/.. _lxml: https://lxml.de/-.. _ElementTree: https://docs.python.org/3/library/xml.etree.elementtree.html.. _XPath: https://www.w3.org/TR/xpath/all/.. _CSS: https://www.w3.org/TR/selectors.. _parsel: https://parsel.readthedocs.io/en/latest/diff --git a/docs/topics/spider-middleware.rst b/docs/topics/spider-middleware.rstindex 3d7450c86..d49a2209d 100644--- a/docs/topics/spider-middleware.rst+++ b/docs/topics/spider-middleware.rst@@ -140,7 +140,7 @@ object gives you access, for example, to the :ref:`settings <topics-settings>`.:type response: :class:`~scrapy.http.Response` object:param exception: the exception raised- :type exception: `Exception`_ object+ :type exception: :exc:`Exception` object:param spider: the spider which raised the exception:type spider: :class:`~scrapy.spiders.Spider` object@@ -183,10 +183,6 @@ object gives you access, for example, to the :ref:`settings <topics-settings>`.:param crawler: crawler that uses this middleware:type crawler: :class:`~scrapy.crawler.Crawler` object--.. _Exception: https://docs.python.org/3/library/exceptions.html#Exception--.. _topics-spider-middleware-ref:Built-in spider middleware referencediff --git a/docs/topics/spiders.rst b/docs/topics/spiders.rstindex 89609db7d..231db6cea 100644--- a/docs/topics/spiders.rst+++ b/docs/topics/spiders.rst@@ -298,9 +298,7 @@ Keep in mind that spider arguments are only strings.The spider will not do any parsing on its own.If you were to set the ``start_urls`` attribute from the command line,you would have to parse it on your own into a list-using something like-`ast.literal_eval <https://docs.python.org/3/library/ast.html#ast.literal_eval>`_-or `json.loads <https://docs.python.org/3/library/json.html#json.loads>`_+using something like :func:`ast.literal_eval` or :func:`json.loads`and then set it as an attribute.Otherwise, you would cause iteration over a ``start_urls`` string(a very common python pitfall)diff --git a/docs/topics/telnetconsole.rst b/docs/topics/telnetconsole.rstindex 47d8d393c..9802a34a2 100644--- a/docs/topics/telnetconsole.rst+++ b/docs/topics/telnetconsole.rst@@ -40,10 +40,10 @@ the console you need to type::Connected to localhost.Escape character is '^]'.Username:- Password:+ Password:>>>-By default Username is ``scrapy`` and Password is autogenerated. The+By default Username is ``scrapy`` and Password is autogenerated. Theautogenerated Password can be seen on Scrapy logs like the example below::2018-10-16 14:35:21 [scrapy.extensions.telnet] INFO: Telnet Password: 16f92501e8a59326@@ -63,7 +63,7 @@ Available variables in the telnet console=========================================The telnet console is like a regular Python shell running inside the Scrapy-process, so you can do anything from it including importing new modules, etc.+process, so you can do anything from it including importing new modules, etc.However, the telnet console comes with some default variables defined forconvenience:@@ -89,13 +89,11 @@ convenience:+----------------+-------------------------------------------------------------------+| ``prefs`` | for memory debugging (see :ref:`topics-leaks`) |+----------------+-------------------------------------------------------------------+-| ``p`` | a shortcut to the `pprint.pprint`_ function |+| ``p`` | a shortcut to the :func:`pprint.pprint` function |+----------------+-------------------------------------------------------------------+| ``hpy`` | for memory debugging (see :ref:`topics-leaks`) |+----------------+-------------------------------------------------------------------+-.. _pprint.pprint: https://docs.python.org/library/pprint.html#pprint.pprint-Telnet console usage examples=============================@@ -208,4 +206,3 @@ Default: ``None``The password used for the telnet console, default behaviour is to have itautogenerated-diff --git a/scrapy/item.py b/scrapy/item.pyindex 1d39b48b2..748368932 100644--- a/scrapy/item.py+++ b/scrapy/item.py@@ -121,9 +121,7 @@ class DictItem(MutableMapping, BaseItem):return self.__class__(self)def deepcopy(self):- """Return a `deep copy`_ of this item.-- .. _deep copy: https://docs.python.org/library/copy.html#copy.deepcopy+ """Return a :func:`~copy.deepcopy` of this item."""return deepcopy(self)