I have a situation where i want to scrape multiple tables across different urls. I did manage to scrape one page, but my function is failing when i try to scrape across pages and stack the tables as a dataframe/list.
library(rvest)
library(tidyverse)
library(purrr)
index <-225:227
urls <- paste0("https://lsgkerala.gov.in/en/lbelection/electdmemberdet/2010/", index)
get_gram <- function(url){
urls %>%
read_html() %>%
html_nodes(xpath = '//*[@id="block-zircon-content"]/a[2]') %>%
html_text() -> temp
urls %>%
read_html() %>%
html_nodes(xpath = '//*[@id="block-zircon-content"]/table') %>%
html_table() %>%
as.data.frame() %>% add_column(newcol=str_c(temp))
}
#results <- map_df(urls,get_gram) Have commented this out, but this is what i
# used to get the table when the index just had one element and it worked.
results <- list()
results[[i]] <- map_df(urls,get_gram)
I think I am faltering at the step where i must stack the map_df output and I thank you in advance for your help!