Return a :class:`~.Request` instance to follow a link ``url``. It accepts the same arguments as ``Request.__init__()`` method, but ``url`` can be not only an absolute URL, but also * a relative URL * a :class:`~scrapy.link.Link` object, e.g. the result of
(
self,
url: str | Link | parsel.Selector,
callback: CallbackT | None = None,
method: str = "GET",
headers: Mapping[AnyStr, Any] | Iterable[tuple[AnyStr, Any]] | None = None,
body: bytes | str | None = None,
cookies: CookiesT | None = None,
meta: dict[str, Any] | None = None,
encoding: str | None = None,
priority: int = 0,
dont_filter: bool = False,
errback: Callable[[Failure], Any] | None = None,
cb_kwargs: dict[str, Any] | None = None,
flags: list[str] | None = None,
)
| 166 | return cast("SelectorList", self.selector.css(query)) |
| 167 | |
| 168 | def follow( |
| 169 | self, |
| 170 | url: str | Link | parsel.Selector, |
| 171 | callback: CallbackT | None = None, |
| 172 | method: str = "GET", |
| 173 | headers: Mapping[AnyStr, Any] | Iterable[tuple[AnyStr, Any]] | None = None, |
| 174 | body: bytes | str | None = None, |
| 175 | cookies: CookiesT | None = None, |
| 176 | meta: dict[str, Any] | None = None, |
| 177 | encoding: str | None = None, |
| 178 | priority: int = 0, |
| 179 | dont_filter: bool = False, |
| 180 | errback: Callable[[Failure], Any] | None = None, |
| 181 | cb_kwargs: dict[str, Any] | None = None, |
| 182 | flags: list[str] | None = None, |
| 183 | ) -> Request: |
| 184 | """ |
| 185 | Return a :class:`~.Request` instance to follow a link ``url``. |
| 186 | It accepts the same arguments as ``Request.__init__()`` method, |
| 187 | but ``url`` can be not only an absolute URL, but also |
| 188 | |
| 189 | * a relative URL |
| 190 | * a :class:`~scrapy.link.Link` object, e.g. the result of |
| 191 | :ref:`topics-link-extractors` |
| 192 | * a :class:`~scrapy.Selector` object for a ``<link>`` or ``<a>`` element, e.g. |
| 193 | ``response.css('a.my_link')[0]`` |
| 194 | * an attribute :class:`~scrapy.Selector` (not SelectorList), e.g. |
| 195 | ``response.css('a::attr(href)')[0]`` or |
| 196 | ``response.xpath('//img/@src')[0]`` |
| 197 | |
| 198 | See :ref:`response-follow-example` for usage examples. |
| 199 | """ |
| 200 | if isinstance(url, parsel.Selector): |
| 201 | url = _url_from_selector(url) |
| 202 | elif isinstance(url, parsel.SelectorList): |
| 203 | raise ValueError("SelectorList is not supported") |
| 204 | encoding = self.encoding if encoding is None else encoding |
| 205 | return super().follow( |
| 206 | url=url, |
| 207 | callback=callback, |
| 208 | method=method, |
| 209 | headers=headers, |
| 210 | body=body, |
| 211 | cookies=cookies, |
| 212 | meta=meta, |
| 213 | encoding=encoding, |
| 214 | priority=priority, |
| 215 | dont_filter=dont_filter, |
| 216 | errback=errback, |
| 217 | cb_kwargs=cb_kwargs, |
| 218 | flags=flags, |
| 219 | ) |
| 220 | |
| 221 | def follow_all( |
| 222 | self, |