提交表单时出现 rvest 错误

rvest error on form submission

我想从以下网页抓取数据:

https://swgoh.gg/u/zozo/collection/180/emperor-palpatine/

当我想访问它时,该网站需要我登录。

这是我的代码:

library(rvest)

url <- 'https://swgoh.gg/u/zozo/collection/180/emperor-palpatine/'
session <- html_session(url)

<session> https://swgoh.gg/accounts/login/?next=/u/zozo/collection/180/emperor-palpatine/

Status: 200

Type: text/html; charset=utf-8

Size: 2081

form <- html_form(read_html(url))[[1]]

<form> '<unnamed>' (POST .)

<input hidden> 'csrfmiddlewaretoken': aFuZy6Pxjg10MqdZjis9vjgojDCxa3QT

<input text> 'username':

<input password> 'password':

<button> '<unnamed>

filled_form <- set_values(form,
                          username = "myusername",
                          password = "mypassword")
(result<-submit_form(session, filled_form))

虽然我的用户名和密码在正常浏览时有效,但在 运行 最后一行后出现以下错误:

Error: Could not find possible submission target.

我已经在网上搜索了解决方案,但没有成功。

编辑:@Mr Flick 提出的解决方案达到了目的。不幸的是,我收到以下警告消息:

Submitting with '<unnamed>'

Warning message:

In request_POST(session, url = url, body = request$values, encode => request$encode, : Forbidden (HTTP 403).

result 给出:

<session> https://swgoh.gg/accounts/login/

Status: 403

Type: text/html; charset=utf-8

Size: 989

rvest 用来确定如何提交表单的代码似乎出错了。它没有将通用 "button" 识别为提交按钮。在这种情况下,你可以用

来愚弄它
form$fields[[4]]$type <- "button"
filled_form <- set_values(form,
                          username = "myusername",
                          password = "mypassword")
submit_form(session, filled_form)