這裏有幾個步驟。首先,填寫表格並提交,然後提取到表格的鏈接,然後閱讀表格。
library("rvest")
library("stringr")
url <- "https://declaraciones.sri.gob.ec/mat-vehicular-internet/reportes/general/valoresAPagar.jsp"
s <- html_session(url)
s_form <- html_form(s)[[2]]
filled_form <- set_values(s_form, placaCamv="pyk0911")
out <- submit_form(session=s, filled_form)
# out contains the link to the data table that pops up. This extracts that link
dat_path <- out %>% html_nodes("input.boton") %>% html_attr("onclick") %>%
.[2] %>% str_extract("(?<=\\(\\').+(?=','avaluos)")
# then read the second table. I assume this is what you need.
df <- read_html(paste0("https://declaraciones.sri.gob.ec", dat_path)) %>%
html_table(fill=TRUE) %>% .[[2]]
> df
PerÃodo Avalúo Impuesto
1 2016 1,699.00 8.50
2 2015 1,699.00 8.50
3 2014 1,699.00 8.50
4 2013 1,699.00 8.50
5 2012 1,699.00 8.50
6 2011 1,699.00 8.50
7 2010 1,699.00 8.50
8 2009 1,699.00 8.50
9 2008 1,699.00 8.50
10 2007 1,699.00 8.50
11 2006 3,398.00 16.99
12 2005 7,036.00 50.36
13 2004 10,554.00 111.08
14 2003 14,072.00 202.16
15 2002 16,990.00 300.00
16 2001 4,000.00 68.00
謝謝@cory工作完美! – Duck