从 R 中的网页打开 PDF

opening PDF from a webpage in R

我正在尝试对美联储 FOMC 会议纪要进行文本分析。

我能够从下面的 link 中获取所有 link 到适当的 pdf 文件。 https://www.federalreserve.gov/monetarypolicy/fomccalendars.htm

我试过了download.file(https://www.federalreserve.gov/monetarypolicy/files/fomcminutes20160316.pdf,"1.pdf").

下载成功;但是,当我单击下载的文件时,它会输出“打开此文档时出错。文件已损坏,无法修复。” 有什么方法可以解决这个问题?这是一种防止美联储方面进行网络抓取的方法吗?

我有 44 links(pdf 文件)要下载并在 R 中阅读。有没有办法在不实际下载文件的情况下执行此操作?

library(stringr)
library(rvest)
library(pdftools)

# Scrape the website with rvest for all href links
p <- 
  rvest::read_html("https://www.federalreserve.gov/monetarypolicy/fomccalendars.htm")
pdfs <- p %>% rvest::html_elements("a") %>% html_attr("href")

# Filter selected fomcminute paths and reconstruct html links
pdfs <- pdfs[stringr::str_detect(pdfs, "fomcminutes.*pdf")]
pdfs <- pdfs[!is.na(pdfs)]
paths <- paste0("https://www.federalreserve.gov/", pdfs)

# Scrape minutes as list of text files
pdf_data <- lapply(paths, pdftools::pdf_text)