Closed nalimilan closed 3 years ago
input[@type="submit"] does not have a name attribute: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/submit
Potentially change https://github.com/tidyverse/rvest/blob/master/R/form.R 112 to use xpath below instead of using the node name of "input". $x('//input[@type!="submit"]')
Could you please rework your reproducible example to use the reprex package ? That makes it easier to see both the input and the output, formatted in such a way that I can easily re-run in a local session.
Hadley,
The assumption that all input tags have name attributes is the root cause of this issue. <input name="namiverse"> However, when they attribute type is submit, i.e., <input type="submit"> There won't be a name attribute. MDN
Currently on line 112 of https://github.com/tidyverse/rvest/blob/master/R/form.R the check is that the tag is input and then assumes there's a name attribute. Whereas the input tag should not have a name tag if the attribute type is equal to submit. This xpath excludes the input tags where the attribute type == submit : '//input[@type!="submit"]'
Instead of stopifnot(inherits(input, "xml_node"), xml2::xml_name(input) == "input")
do stopifnot(inherits(input, "xml_node"), is.na(xml2::xml_find_first(input, '//input[@type!="submit"]')))
@lifesabirch a reprex is very useful because I can then turn that in a test to make sure this issue doesn't happen again. Alternatively, would you be interested in doing a PR?
Hadley,
I'd be happy to do both. I'll learn and do reprex tomorrow night!
I think this should be resolved now, as part of a general revamping of the form code, please let me if not.
Thanks!
I've hit a website where
submit_form
fails because the form has a single button with no name. So it it sendscu=XX&mp=YY&NULL=OK
, while just sendingcu=XX&mp=YY
works. Below is a reproducer and an illustration of how it works when usingrequest_POST
directly without the&NULL=OK
part.