Skip to content

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

Document missing parts of response.json method

Laerte Pereira144ff6c756fa
diff --git a/docs/topics/dynamic-content.rst b/docs/topics/dynamic-content.rst
index a0f4b4411..a99f1e222 100644
--- a/docs/topics/dynamic-content.rst
+++ b/docs/topics/dynamic-content.rst
@@ -115,15 +115,14 @@ Handling different response formats
Once you have a response with the desired data, how you extract the desired
data from it depends on the type of response:
-- If the response is HTML or XML, use :ref:`selectors
+- If the response is HTML, XML or JSON, use :ref:`selectors
<topics-selectors>` as usual.
-- If the response is JSON, use :func:`json.loads` to load the desired data from
- :attr:`response.text <scrapy.http.TextResponse.text>`:
+- If the response is JSON, use :func:`response.json()` to load the desired data:
.. code-block:: python
- data = json.loads(response.text)
+ data = response.json()
If the desired data is inside HTML or XML code embedded within JSON data,
you can load that HTML or XML code into a
diff --git a/docs/topics/selectors.rst b/docs/topics/selectors.rst
index e32fc2b70..0aae41cc8 100644
--- a/docs/topics/selectors.rst
+++ b/docs/topics/selectors.rst
@@ -1060,6 +1060,12 @@ Selector objects
For convenience, this method can be called as ``response.css()``
+ .. automethod:: jmespath
+
+ .. note::
+
+ For convenience, this method can be called as ``response.jmespath()``
+
.. automethod:: get
See also: :ref:`old-extraction-api`
@@ -1092,6 +1098,8 @@ SelectorList objects
.. automethod:: css
+ .. automethod:: jmespath
+
.. automethod:: getall
See also: :ref:`old-extraction-api`
diff --git a/scrapy/selector/unified.py b/scrapy/selector/unified.py
index e852aadc7..bfddb87cb 100644
--- a/scrapy/selector/unified.py
+++ b/scrapy/selector/unified.py
@@ -59,6 +59,7 @@ class Selector(_ParselSelector, object_ref):
* ``"html"`` for :class:`~scrapy.http.HtmlResponse` type
* ``"xml"`` for :class:`~scrapy.http.XmlResponse` type
+ * ``"json"`` for :class:`~scrapy.http.TextResponse` type
* ``"html"`` for anything else
Otherwise, if ``type`` is set, the selector type will be forced and no