我使用 rvest
读取了一个 html 表单并想设置一个复选框值:
library(rvest)
url <- 'https://www.signupgenius.com/go/10c0f4fadac2ea6fac52-release825'
html_form(session(url))[[1]]
<form> 'signupForm' (POST https://www.signupgenius.com/index.cfm?go=s.PreProcessSignup)
<field> (hidden) URLID: 10C0F4FADAC2EA6FA...
<field> (hidden) useMultiple: true
<field> (hidden) siids:
<field> (checkbox) siid: 962826833
我想知道如何使用 set_values()
将复选框的值设置为 true。
最佳答案
提交表单的过程包括创建 session 、检索表单、更新值、提交和跳转到下一页。
#Based on rvest >1.0.0
library(rvest)
url <- 'https://www.signupgenius.com/go/10c0f4fadac2ea6fac52-release825'
#create the session and retrieve the form
pgsession<-session(url)
pgform<-html_form(pgsession)[[1]]
#https://github.com/r-lib/xml2/issues/34
pgform$url<-""
#create the response and set the value of checkbox to TRUE
#another option to try: siid=1
filled_form<-html_form_set(pgform, siid=TRUE)
#Submitt the form
session_submit(pgsession, filled_form, submit=NULL)
#may need to manually naviage to the next page
#next_page<-jump_to(pgsession,"https://www.signupgenius.com/index.cfm?go=s.ProcessSignup&urlid=10C0F4FADAC2EA6FAC52-release825")
试一试,它应该有效。如果没有,请告诉我以防需要更新。
关于r - 如何在 R 中的 rvest::set_values() 中设置复选框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68898923/