Create a Request object from a string containing a `cURL <https://curl.se/>`_ command. It populates the HTTP method, the URL, the headers, the cookies and the body. It accepts the same arguments as the :class:`Request` class, taking preference and overriding the value
(
cls,
curl_command: str,
ignore_unknown_options: bool = True,
**kwargs: Any,
)
| 339 | |
| 340 | @classmethod |
| 341 | def from_curl( |
| 342 | cls, |
| 343 | curl_command: str, |
| 344 | ignore_unknown_options: bool = True, |
| 345 | **kwargs: Any, |
| 346 | ) -> Self: |
| 347 | """Create a Request object from a string containing a `cURL |
| 348 | <https://curl.se/>`_ command. It populates the HTTP method, the |
| 349 | URL, the headers, the cookies and the body. It accepts the same |
| 350 | arguments as the :class:`Request` class, taking preference and |
| 351 | overriding the values of the same arguments contained in the cURL |
| 352 | command. |
| 353 | |
| 354 | Unrecognized options are ignored by default. To raise an error when |
| 355 | finding unknown options call this method by passing |
| 356 | ``ignore_unknown_options=False``. |
| 357 | |
| 358 | .. caution:: Using :meth:`from_curl` from :class:`~scrapy.Request` |
| 359 | subclasses, such as :class:`~scrapy.http.JsonRequest`, or |
| 360 | :class:`~scrapy.http.XmlRpcRequest`, as well as having |
| 361 | :ref:`downloader middlewares <topics-downloader-middleware>` |
| 362 | and |
| 363 | :ref:`spider middlewares <topics-spider-middleware>` |
| 364 | enabled, such as |
| 365 | :class:`~scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware`, |
| 366 | :class:`~scrapy.downloadermiddlewares.useragent.UserAgentMiddleware`, |
| 367 | or |
| 368 | :class:`~scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware`, |
| 369 | may modify the :class:`~scrapy.Request` object. |
| 370 | |
| 371 | To translate a cURL command into a Scrapy request, |
| 372 | you may use `curl2scrapy <https://michael-shub.github.io/curl2scrapy/>`_. |
| 373 | """ |
| 374 | request_kwargs = curl_to_request_kwargs(curl_command, ignore_unknown_options) |
| 375 | request_kwargs.update(kwargs) |
| 376 | return cls(**request_kwargs) |
| 377 | |
| 378 | def to_dict(self, *, spider: scrapy.Spider | None = None) -> dict[str, Any]: |
| 379 | """Return a dictionary containing the Request's data. |