mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-24 22:23:46 +00:00
Add Response.urljoin() helper
This commit is contained in:
parent
c81eefaf81
commit
cda3922507
@ -493,6 +493,18 @@ Response objects
|
|||||||
given new values by whichever keyword arguments are specified. The
|
given new values by whichever keyword arguments are specified. The
|
||||||
attribute :attr:`Response.meta` is copied by default.
|
attribute :attr:`Response.meta` is copied by default.
|
||||||
|
|
||||||
|
.. method:: Response.urljoin(url)
|
||||||
|
|
||||||
|
Constructs an absolute url by combining the Response's :attr:`url` with
|
||||||
|
a possible relative url.
|
||||||
|
|
||||||
|
This is a wrapper over `urlparse.urljoin`_, it's merely an alias for
|
||||||
|
making this call::
|
||||||
|
|
||||||
|
urlparse.urljoin(response.url, url)
|
||||||
|
|
||||||
|
.. _urlparse.urljoin: https://docs.python.org/2/library/urlparse.html#urlparse.urljoin
|
||||||
|
|
||||||
.. _topics-request-response-ref-response-subclasses:
|
.. _topics-request-response-ref-response-subclasses:
|
||||||
|
|
||||||
Response subclasses
|
Response subclasses
|
||||||
|
@ -7,6 +7,8 @@ See documentation in docs/topics/request-response.rst
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
from six.moves.urllib.parse import urljoin
|
||||||
|
|
||||||
from scrapy.http.headers import Headers
|
from scrapy.http.headers import Headers
|
||||||
from scrapy.utils.trackref import object_ref
|
from scrapy.utils.trackref import object_ref
|
||||||
from scrapy.http.common import obsolete_setter
|
from scrapy.http.common import obsolete_setter
|
||||||
@ -75,3 +77,8 @@ class Response(object_ref):
|
|||||||
kwargs.setdefault(x, getattr(self, x))
|
kwargs.setdefault(x, getattr(self, x))
|
||||||
cls = kwargs.pop('cls', self.__class__)
|
cls = kwargs.pop('cls', self.__class__)
|
||||||
return cls(*args, **kwargs)
|
return cls(*args, **kwargs)
|
||||||
|
|
||||||
|
def urljoin(self, url):
|
||||||
|
"""Join this Response's url with a possible relative url to form an
|
||||||
|
absolute interpretation of the latter."""
|
||||||
|
return urljoin(self.url, url)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user