表单提交时出现错误 [英] rvest error on form submission
问题描述
我想从以下网页中删除数据:
https://swgoh.gg/u/zozo/collection/180/皇帝-帕尔帕廷/
当我想访问它时,该网站需要我登录.
这是我的代码:
库(rvest)网址 <- 'https://swgoh.gg/u/zozo/collection/180/emperor-palpatine/'会话 <- html_session(url)
<块引用>
<会话>https://swgoh.gg/accounts/login/?next=/u/zozo/collection/180/emperor-palpatine/
状态:200
类型:文本/html;字符集=utf-8
尺寸:2081
form <- html_form(read_html(url))[[1]]
<块引用>
<表单>'<未命名>'(发布.)
<输入隐藏>'csrfmiddlewaretoken':aFuZy6Pxjg10MqdZjis9vjgojDCxa3QT
<输入文本>'用户名':
<输入密码> '密码':
<按钮>'<未命名>
filled_form <- set_values(form,用户名 = "我的用户名",密码 = "我的密码")(结果<-submit_form(session,filled_form))
虽然我的用户名和密码在正常浏览时有效,但运行最后一行后出现以下错误:
<块引用>错误:找不到可能的提交目标.
我已经在网上搜索了一个解决方案,但没有成功.
@Mr Flick 提出的解决方案成功了.不幸的是,我收到以下警告消息:
<块引用>使用
警告信息:
在 request_POST(session, url = url, body = request$values, encode => request$encode, :禁止 (HTTP 403).
result
给出:
<会话>https://swgoh.gg/accounts/login/
状态:403
类型:文本/html;字符集=utf-8
尺寸:989
rvest
用于确定如何提交表单的代码似乎被绊倒了.它没有将通用按钮"识别为提交按钮.在这种情况下,你可以用
form$fields[[4]]$type <-按钮"Filled_form <- set_values(form,用户名 = "我的用户名",密码 = "我的密码")提交表单(会话,填充表单)
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
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)
这篇关于表单提交时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!