MCPcopy
hub / github.com/scrapy/scrapy / _get_inputs

Function _get_inputs

scrapy/http/request/form.py:168–204  ·  view source on GitHub ↗

Return a list of key-value pairs for the inputs found in the given form.

(
    form: FormElement,
    formdata: FormdataType,
    dont_click: bool,
    clickdata: dict[str, str | int] | None,
)

Source from the content-addressed store, hash-verified

166
167
168def _get_inputs(
169 form: FormElement,
170 formdata: FormdataType,
171 dont_click: bool,
172 clickdata: dict[str, str | int] | None,
173) -> list[FormdataKVType]:
174 """Return a list of key-value pairs for the inputs found in the given form."""
175 try:
176 formdata_keys = dict(formdata or ()).keys()
177 except (ValueError, TypeError):
178 raise ValueError("formdata should be a dict or iterable of tuples") from None
179
180 if not formdata:
181 formdata = []
182 inputs = form.xpath(
183 "descendant::textarea"
184 "|descendant::select"
185 "|descendant::input[not(@type) or @type["
186 ' not(re:test(., "^(?:submit|image|reset)$", "i"))'
187 " and (../@checked or"
188 ' not(re:test(., "^(?:checkbox|radio)$", "i")))]]',
189 namespaces={"re": "http://exslt.org/regular-expressions"},
190 )
191 values: list[FormdataKVType] = [
192 (k, "" if v is None else v)
193 for k, v in (_value(e) for e in inputs)
194 if k and k not in formdata_keys
195 ]
196
197 if not dont_click:
198 clickable = _get_clickable(clickdata, form)
199 if clickable and clickable[0] not in formdata and clickable[0] is not None:
200 values.append(clickable)
201
202 formdata_items = formdata.items() if isinstance(formdata, dict) else formdata
203 values.extend((k, v) for k, v in formdata_items if v is not None)
204 return values
205
206
207def _value(

Callers 1

from_responseMethod · 0.85

Calls 6

_valueFunction · 0.85
_get_clickableFunction · 0.85
keysMethod · 0.80
itemsMethod · 0.80
xpathMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected