| 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 | |
| 105 | def _get_form_url(form: FormElement, url: str | None) -> str: |