Reputation: 161
I would like to download all the zip files form this website using R. However, I would like to download "Relatório por município" and "Relatório por município e agência" separately. How can I do it?
Upvotes: 0
Views: 50
Reputation: 389265
You can use :
library(rvest)
url <- 'https://www4.bcb.gov.br/fis/cosif/estban.asp?frame=1'
#Read webpage
webpage <- url %>% read_html()
#Extract links to download from "Relatório por município"
links1 <- webpage %>%
html_nodes('div.centralizado select#ESTBAN_MUNICIPIO option') %>%
html_attr('value') %>%
paste0('https://www4.bcb.gov.br', .)
#Download the files
lapply(links1, function(x) download.file(x, paste0('ESTBAN_MUNICIPIO/', basename(x))))
#Extract links to download from "Relatório por município e agência"
links2 <- webpage %>%
html_nodes('div.centralizado select#ESTBAN_AGENCIA option') %>%
html_attr('value') %>%
paste0('https://www4.bcb.gov.br', .)
#Download the files
lapply(links2, function(x) download.file(x, paste0('ESTBAN_AGENCIA/', basename(x))))
Upvotes: 1