rvest:"unknown field names" 尝试设置表单时
rvest: "unknown field names" when attempting to set form
我正在尝试生成一个 Web 表单以允许我抓取数据。
library(rvest)
url <- "https://iemweb.biz.uiowa.edu/pricehistory/pricehistory_SelectContract.cfm?market_ID=214"
pg.form <- html_form(html(url))
哪个returns
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
我的错误是认为我需要为 Month
和 Year
字段设置值,但这是一个错误
filled_form <- set_values(pg.form,
Month = "8",
Year = "0")
returns Error: Unknown field names: Month, Year
如何使用 rvest
在网络表单中设置值?
从你的输出来看,pg.form
实际上是一个列表形式,而不是一个单一的形式。要访问第一个表单,请执行
set_values(pg.form[[1]], Month="8")
或者你也可以
pg.form <- html_form(html(pg.session))[[1]]
相反。
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'
我正在尝试生成一个 Web 表单以允许我抓取数据。
library(rvest)
url <- "https://iemweb.biz.uiowa.edu/pricehistory/pricehistory_SelectContract.cfm?market_ID=214"
pg.form <- html_form(html(url))
哪个returns
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
我的错误是认为我需要为 Month
和 Year
字段设置值,但这是一个错误
filled_form <- set_values(pg.form,
Month = "8",
Year = "0")
returns Error: Unknown field names: Month, Year
如何使用 rvest
在网络表单中设置值?
从你的输出来看,pg.form
实际上是一个列表形式,而不是一个单一的形式。要访问第一个表单,请执行
set_values(pg.form[[1]], Month="8")
或者你也可以
pg.form <- html_form(html(pg.session))[[1]]
相反。
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'