I want to web scrape stocks’ financial tables for different years with R. However, I can obtain the financial tables for the last year, which appears as default. But I also want to obtain data from previous years. How can I achieve this? Here is the code I use:
# Load libraries
library(tidyverse)
library(rvest)
library(readxl)
library(magrittr)
google_finance <- read_html("https://www.google.com/finance/quote/AAPL:NASDAQ?") |>
html_node(".UulDgc") |>
html_table()
And the result is:
> google_finance |>
+ head(5)
# A tibble: 5 × 3
`(USD)` Mar 2024infoFiscal Q…¹ `Y/Y change`
<chr> <chr> <chr>
1 "RevenueThe tot… 90.75B -4.31%
2 "Operating expe… 14.37B 5.22%
3 "Net incomeComp… 23.64B -2.17%
4 "Net profit mar… 26.04 2.20%
5 "Earnings per s… 1.53 0.66%
As you can see, we can only see the financial tables of the last period (March 2024). In this case, what should we do to scrape the financial tables for all years?