我想從這個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/ –