MCPcopy
hub / github.com/scrapy/scrapy / from_response

Method from_response

scrapy/http/request/form.py:74–102  ·  view source on GitHub ↗
(
        cls,
        response: TextResponse,
        formname: str | None = None,
        formid: str | None = None,
        formnumber: int = 0,
        formdata: FormdataType = None,
        clickdata: dict[str, str | int] | None = None,
        dont_click: bool = False,
        formxpath: str | None = None,
        formcss: str | None = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

72
73 @classmethod
74 def from_response(
75 cls,
76 response: TextResponse,
77 formname: str | None = None,
78 formid: str | None = None,
79 formnumber: int = 0,
80 formdata: FormdataType = None,
81 clickdata: dict[str, str | int] | None = None,
82 dont_click: bool = False,
83 formxpath: str | None = None,
84 formcss: str | None = None,
85 **kwargs: Any,
86 ) -> Self:
87 kwargs.setdefault("encoding", response.encoding)
88
89 if formcss is not None:
90 formxpath = HTMLTranslator().css_to_xpath(formcss)
91
92 form = _get_form(response, formname, formid, formnumber, formxpath)
93 formdata = _get_inputs(form, formdata, dont_click, clickdata)
94 url = _get_form_url(form, kwargs.pop("url", None))
95
96 method = kwargs.pop("method", form.method)
97 if method is not None:
98 method = method.upper()
99 if method not in cls.valid_form_methods:
100 method = "GET"
101
102 return cls(url=url, method=method, formdata=formdata, **kwargs)
103
104
105def _get_form_url(form: FormElement, url: str | None) -> str:

Calls 5

_get_formFunction · 0.85
_get_inputsFunction · 0.85
_get_form_urlFunction · 0.85
setdefaultMethod · 0.45
popMethod · 0.45