Document TextResponse.base_url

This commit is contained in:
Adrián Chaves 2023-01-10 21:27:58 +01:00
parent 7bb5289ced
commit 9ee2ebea54
2 changed files with 9 additions and 1 deletions

View File

@ -1203,6 +1203,8 @@ TextResponse objects
.. autoattribute:: TextResponse.attributes
.. autoattribute:: TextResponse.base_url
:class:`TextResponse` objects support the following methods in addition to
the standard :class:`Response` ones:

View File

@ -95,7 +95,13 @@ class TextResponse(Response):
@property
def base_url(self) -> str:
"""Base URL"""
"""Base URL for any relative URL in the response.
It defaults to the response :attr:`~scrapy.http.Response.url`, but HTML
responses may include a `base element
<https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base>`_ with
a different base URL.
"""
if self._cached_base_url is None:
self._cached_base_url = get_base_url(
self.text[:4096],