简体   繁体   English

在R中提交html表单

[英]submitting html forms in R

I am trying to scrape https://www.fbo.gov/ for academic reasons and cannot figure out how to fill out the search filter and submit from the landing page to scrape a pre-filtered list. 出于学术原因,我正在尝试抓取https://www.fbo.gov/ ,并且无法弄清楚如何填写搜索过滤器并从目标网页提交以抓取预先过滤的列表。 I would like to filter by Place of Performance = West Virginia. 我想按绩效地点=西弗吉尼亚州过滤。 Here is what I have so far 这是我到目前为止的

library(tidyverse)  
library(rvest)    
library(stringr)   
library(rebus)     
library(lubridate)
library(Rcrawler)
library(xml2)
library(devtools)


url <- "https://www.fbo.gov/"
web_session <- html_session(url)

# Get forms with searchable fields in current session.
form <- html_form(web_session)


# First, Copy form.
filled.form <- form

# Set values in form #1
filled.form[[1]] <- set_values(filled.form[[1]],
                               dnf_class_values[procurement_notice][zipstate] 
                                   = "West Virginia")  

# Set form url to empty character string to prevent error message when
filled.form[[1]]$url <- ""

When I run this, I get the error below 运行此命令时,出现以下错误

Error: unexpected '=' in: 错误:出现意外的“ =”:

"filled.form[[1]] <- set_values(filled.form[[1]],
                               dnf_class_values[procurement_notice][zipstate] ="

I have tried this same method and to submit with other examples and am also having trouble submitting the form to make it run. 我尝试了相同的方法并提交了其他示例,并且在提交表单以使其运行时也遇到了麻烦。 How can I fill out the form and submit it so that I can scrape a subset of WV opportunities? 我如何填写表格并提交,这样我就可以抓取一部分WV机会?

Try putting the form field in quotes: 尝试将表单字段放在引号中:

"dnf_class_values[procurement_notice][zipstate]" = "WV"

You can get more details about the form with: 您可以通过以下方式获取有关表格的更多详细信息:

str(filled.form[[1]])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM