rvest error on form submission

萝らか妹 提交于 2021-02-05 08:19:27

问题


I would like to scrap data from the following webpage:

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

When I want to access it, the website requires my login.

Here is my code:

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))

Although my username and password works when I browse normally, I get the following error after running the last line:

Error: Could not find possible submission target.

I have already searched the web for a solution without success.

EDIT : The solution proposed by @Mr Flick did the trick. unfortunately, I get the following warning message :

Submitting with '<unnamed>'

Warning message:

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

result gives :

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

Status: 403

Type: text/html; charset=utf-8

Size: 989


回答1:


The code that rvest uses to determine how to submit the form seems to be getting tripped up. it's not recognizing the generic "button" as the submit button. You can fool it in this case with

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


来源:https://stackoverflow.com/questions/50865426/rvest-error-on-form-submission

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