我正在尝试生成一个Web表单以允许我刮擦数据。
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
我的错误是认为我需要为Month
和Year
字段设置值,但这是一个错误
filled_form <- set_values(pg.form,
Month = "8",
Year = "0")
返回Error: Unknown field names: Month, Year
如何使用rvest
在WebForm中设置值?
从您的输出中,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'