API reference
- form2request.form2request(form: FormElement | Selector | SelectorList, data: FormdataType = None, *, click: None | bool | HtmlElement = None, method: None | str = None, enctype: None | str = None) Request
Return request data for an HTML form submission.
form must be an instance of
parsel.selector.Selector
orparsel.selector.SelectorList
that points to an HTML form, or an instance oflxml.html.FormElement
.data should be either a dictionary or a list of 2-item tuples indicating the key-value pairs to include in the request as submission data. Keys with
None
as value exclude matching form fields.click can be any of:
None
(default): the first submission element of the form (e.g. a submit button) is used to build a request for a click-based form submission.If no submission elements are found, the request is built for a non-click-based form submission, i.e. a form submission triggered by a non-click event, such as pressing the Enter key while the focus is in a single-line text input field of the form.
True
behaves likeNone
, but raises aValueError
exception if no submission element is found in the form.False
builds a request for a non-click-based form submission.A submit button of form, to build a request for a form submission based on the clicking of that button.
On forms with multiple submit buttons, specifying the right button here may be necessary.
method and enctype may be used to override matching form attributes.
- class form2request.Request(url: str, method: str, headers: list[tuple[str, str]], body: bytes)
HTTP request data.
- to_poet(**kwargs)
Convert the request to
web_poet.HttpRequest
.All kwargs are passed to
web_poet.HttpRequest
as is.
- to_requests(**kwargs)
Convert the request to
requests.PreparedRequest
.All kwargs are passed to
requests.Request
as is.
- to_scrapy(callback, **kwargs)
Convert the request to
scrapy.Request
.All kwargs are passed to
scrapy.Request
as is.