How to set checkbox value in rvest::set_values() in R

Viewed 143

I read a html form using rvest and wanted to set a checkbox value:
enter image description here

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

I'm wondering how to set the checkbox value to true using set_values().

1 Answers

The process of submitting the a form involves creating a session, retrieving the form, updating the value, submitting and jumping to the next page.

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

Give this a try, it should work. If not please let me know in case it needs an update.

Related