“错误:与 STRSXP 不兼容"在带有 rvest 的 submit_form 上 [英] "Error: not compatible with STRSXP" on submit_form with rvest

查看:27
本文介绍了“错误:与 STRSXP 不兼容"在带有 rvest 的 submit_form 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 stackoverflow 和 github 上搜索过,但没有找到解决方案.

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.

任何帮助将不胜感激!

推荐答案

我自己刚遇到这个问题,我发现错误发生在 submit_form() 调用函数 rvest:::submit_request() 时,它试图运行这一行:

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)

在这一行中,R 尝试创建一个绝对 url,它会抛出错误,因为 form$url 或 session$url 为 NULL.就我而言, session$url 由于某种原因为 NULL.所以你应该试试:

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)

这篇关于“错误:与 STRSXP 不兼容"在带有 rvest 的 submit_form 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆