I have created the following script based on the information provided by this link Extract data URL with javascript (table in php)
code
library(httr) library(rvest) library(janitor) library(dplyr) library(purrr)
headers <- c("Content-Type" = "application/x-www-form-urlencoded; charset=UTF-8")
data <- "vid_tipo=1&vprod=&vvari=&vfecha=22/06/2022"
for (i in seq_along(fechas)) {
r <- httr::POST(
url = "http://old.emmsa.com.pe/emmsa_spv/app/reportes/ajax/rpt07_gettable.php",
httr::add_headers(.headers = headers),
body = data
)
t <- content(r) %>%
html_element(".timecard") %>%
html_table() %>%
row_to_names(1) %>%
clean_names() %>%
dplyr::filter(producto != "") %>%
mutate_at(vars(matches("precio")), as.numeric) %>%
as_tibble() -> precios
timestamp <- 1:seq_along(i)
filename <- paste0("c:/Users/.../Desktop/data/precios_",timestamp,".rds")
saveRDS(precios, file = filename)
}```
My problem is that this sequence that I have created by looking at other links in this page has not allowed me to obtain the following results:
1.-Scrape the page according to the sequence of dates;
2.- include the date in the file name such as "data_22-06-2022";
3.- I don't know how to link the date of the variable
`data <- "vid_tipo=1&vprod=&vvari=&vfecha=22/06/2022"`
with the sequence of one file for each date;
4.- Any improvements to the file download and save function are welcome.
Thank you