Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Error: not compatible with STRSXP" on submit_form with rvest

I've searched around stackoverflow and github but haven't seen a solution to this one.

session <- read_html("http://www.whitepages.com")
form1 <- html_form(session)[[1]]
form2 <- set_values(form1, who = "john smith")
submit_form(session, form)

After the submit form line, I get the following:

Submitting with '<unnamed>'
Error: not compatible with STRSXP

I've pieced together that this error is usually from mismatched types (strings and numeric, for example), but I can't tell where that might be happening.

Any help would be greatly appreciated!

like image 568
Craig Maas Avatar asked Jan 07 '23 22:01

Craig Maas


2 Answers

I just had this problem myself, and I found that the error was happening when submit_form() called the function rvest:::submit_request(), which tries to run this line:

xml2::url_absolute(form$url, session$url)

In this line, R tries to create an absolute url which throws an error because either form$url or session$url is NULL. In my case, session$url was NULL for some reason. So you should probably try:

session$url <- "http://www.whitepages.com"
submit_form(session, form2)
like image 126
Amadou Kone Avatar answered Jan 30 '23 23:01

Amadou Kone


Try to change the URL of your form into an empty string form2$url <- "" before submitting it.

like image 20
OAA Avatar answered Jan 30 '23 23:01

OAA