r - 如何在 R 中的 rvest::set_values() 中设置复选框值

标签 r rvest

我使用 rvest 读取了一个 html 表单并想设置一个复选框值:
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

我想知道如何使用 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/

相关文章:

r - 比较同一向量的相邻元素(避免循环)

html - 如何使用 Rvest 抓取带有嵌套列的 HTML 表格?

html - Facebook 上的 R、rvest 和 selectorGadget

r - 使用并行的 parLapply : unable to access variables within parallel code

r - 不起作用的 ggplot alphas

r - 如何在 r 中的多个点拆分字符串列?

css - 到达 css 节点时遇到问题

r - 使用dplyr连接两个数据帧时可以替换NA吗?

r - 抓取请求 rvest 同意 cookie 的站点

r - 使用 rvest 在 R 中进行 Web 抓取并找到 html_note