【问题标题】:rvest: "unknown field names" when attempting to set formrvest:尝试设置表单时出现“未知字段名称”
【发布时间】:2015-05-10 01:22:44
【问题描述】:

我正在尝试生成一个网络表单以允许我抓取数据。

library(rvest)

url <- "https://iemweb.biz.uiowa.edu/pricehistory/pricehistory_SelectContract.cfm?market_ID=214"

pg.form <- html_form(html(url))

返回

pg.form
[[1]]
<form> '<unnamed>' (POST PriceHistory_GetData.cfm)
 <input HIDDEN> 'Market_ID': 214
 <select> 'Month' [1/12]
 <select> 'Year' [0/2]
 <input SUBMIT> '': Get Prices

我的错误是认为我需要为 MonthYear 字段设置值,但这是一个错误

filled_form <- set_values(pg.form,
                          Month = "8",
                          Year = "0")

返回Error: Unknown field names: Month, Year

如何使用rvest 在网络表单中设置值?

【问题讨论】:

    标签: r web-scraping rvest


    【解决方案1】:

    从您的输出来看,pg.form 实际上是一个列表表单,而不是单个表单。要访问第一个表单,请执行以下操作

    set_values(pg.form[[1]], Month="8")
    

    或者你可以这样做

    pg.form <- html_form(html(pg.session))[[1]]
    

    改为。

    【讨论】:

      【解决方案2】:
      lnk3 <- 'http://data.nowgoal.com/history/handicap.htm' #this website content includes the odds price
      > sess <- html_session(lnk3)
      > f0 <- sess %>% html_form
      > f1 <- set_values(f0[[2]], matchdate=dateID[1], companyid1=list(c(3,8,4,12,1,23,24,17,31,14,35,22)))
      Warning message:
      Setting value of hidden field 'companyid1'. 
      > s <- submit_form(sess, f1)
      Submitting with 'NULL'
      

      试图提交一个隐藏字段但听起来不起作用的表单,提交时使用'NULL'

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多