I have been happily web scraping yahoo.finance pages for a long time using code largely borrowed from other stackoverflow answers and it has worked great, however in the last few weeks Yahoo has changed their tables to be collapsible/expandable tables. This has broken the code, and despite my best efforts for a few days I can't fix the bug.
Here is an example of the code that others have used for years (which is then parsed and processed in different ways by different people).
library(rvest)
library(tidyverse)
# Create a URL string
myURL <- "https://finance.yahoo.com/quote/AAPL/financials?p=AAPL"
# Create a dataframe called df to hold this income statement called df
df <- myURL %>%
read_html() %>%
html_table(header = TRUE) %>%
map_df(bind_cols) %>%
as_tibble()
Can anyone help?
EDIT FOR MORE CLARITY:
If you run the above then view df you get
# A tibble: 0 x 0
For an example of the expected outcome, we can try another page yahoo hasn't changed such as the following:
# Create a URL string
myURL2 <- "https://finance.yahoo.com/quote/AAPL/key-statistics?p=AAPL"
df2 <- myURL2 %>%
read_html() %>%
html_table(header = FALSE) %>%
map_df(bind_cols) %>%
as_tibble()
If you view df2 you get a tibble of 59 observations of two variables being the main table on that page, beginning with
Market Cap (intraday)5 [value here] Enterprise value 3 [value here] And so on...
