“Error: not compatible with STRSXP” on submit_form with rvest

自作多情 提交于 2020-01-02 19:08:33

问题


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!


回答1:


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)



回答2:


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



来源:https://stackoverflow.com/questions/31501108/error-not-compatible-with-strsxp-on-submit-form-with-rvest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!