使用 R 从 url 下载几个文件
Download several files from a url using R
我想使用 R 下载此 website 中的所有 zip 文件。但是,我想单独下载“市政当局报告”和“市政当局和机构报告”。我该怎么做?
您可以使用:
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))))
我想使用 R 下载此 website 中的所有 zip 文件。但是,我想单独下载“市政当局报告”和“市政当局和机构报告”。我该怎么做?
您可以使用:
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))))