Вы можете использовать следующую функцию, чтобы получить фрейм данных со столбцами для даты, заголовка, докладчика и места проведения, которые будут скопированы со страницы с соответствующими терминами xpath. Все, что вам нужно сделать, это кормить его год, который вы хотите.
Примечание. Я использовал пакет rvest, поскольку пакет Rcrawler, по-видимому, не возвращал правильные результаты с теми же значениями xpath:
library(rvest)
library(tibble)
get_fed_speeches <- function(year = substr(date(), 21, 25))
{
scrape <- function(x, page) html_text(html_nodes(read_html(page), xpath = x))
page <- paste0("https://www.federalreserve.gov/newsevents/speech/",
year,
"-speeches.htm")
xpaths <- list(date = "//time",
title = "//div[@class = 'row eventlist']//em",
speaker = "//p[@class = 'news__speaker']",
venue = "//p[@class = 'news__speaker']/following-sibling::p")
as_tibble(lapply(xpaths, scrape, page))
}
Обратите внимание, что по умолчанию используется текущий год, поэтому чтобы получить речи за 2020 год, просто выполните:
get_fed_speeches()
# A tibble: 4 x 4
# date title speaker venue
# <chr> <chr> <chr> <chr>
# 1 1/17/2~ Spontaneity and Order: Trans~ Vice Chair for S~ At the American Bar Associa~
# 2 1/16/2~ The Outlook for Housing Governor Michell~ At the 2020 Economic Foreca~
# 3 1/9/20~ U.S. Economic Outlook and Mo~ Vice Chair Richa~ At the C. Peter McColough S~
# 4 1/8/20~ Strengthening the Community ~ Governor Lael Br~ At the Urban Institute, Was~
или на 2015 год выполните:
get_fed_speeches(2015)
#> # A tibble: 54 x 4
#> date title speaker venue
#> <chr> <chr> <chr> <chr>
#> 1 12/3/2~ Financial Stability and Sha~ Vice Chairman~ "At the \"Financial Stability:~
#> 2 12/2/2~ The Economic Outlook and Mo~ Chair Janet L~ At the Economic Club of Washin~
#> 3 12/2/2~ Opening Remarks Governor Dani~ At the Economic Growth and Reg~
#> 4 12/1/2~ Normalizing Monetary Policy~ Governor Lael~ At the Stanford Institute for ~
#> 5 11/20/~ Opening Remarks Governor Jero~ At the 2015 Roundtable on Trea~
#> 6 11/19/~ Emerging Asia in Transition Vice Chairman~ "At the \"Policy Challenges in~
#> 7 11/17/~ Thinking Critically about N~ Governor Dani~ At the Brookings Institution, ~
#> 8 11/17/~ Central Clearing in an Inte~ Governor Jero~ At the Clearing House Annual C~
#> 9 11/12/~ The Transmission of Exchang~ Vice Chairman~ "At the \"Monetary Policy Impl~
#> 10 11/12/~ Welcoming Remarks Chair Janet L~ "At the \"Monetary Policy Impl~
#> # ... with 44 more rows