我想从这个site中提取失业率数据。在表单中,有一个select
标签有一些选项。我可以从默认的2007年到2017年提取表格。但是我很难为from_year
和to_year
设置一个值。这是我到目前为止的代码:rvest:选择一个选项并提交表格
session = html_session("https://data.bls.gov/timeseries/LNS14000000")
form = read_html("https://data.bls.gov/timeseries/LNS14000000") %>% html_node("table form") %>% html_form()
set_values(form, from_year = 2000, to_year = as.numeric(format(Sys.Date(), "%Y"))) # nothing happened if I set the value for years
submit_form(session, form)
它没有按预期工作。
我不认为你可以做到这一点,而不使用'RSelenium'之类的东西。 这里的例子... https://stackoverflow.com/questions/43307090/how-to-select-dropdown-box-using-rselenium/43307980#43307980 但是,我注意到在这种情况下,bls有一个API,所以这可能是值得一看... https://www.bls.gov/developers/ –