hey guys.
I don`t know this code going work. can you help me for a minute?
yesterday i create code below.
-------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
first. [ff <- get_yahoo("CCL", "statistics")]? it`s okay.
but [get_yahoo("CCL", "financials")] is doesn't work!!!
i need scraping yahoo finance financials data table.{financials/balance-sheet/cash-flow}
so I wonder what went wrong in the code above.
please reply.
i need help.
I don`t know this code going work. can you help me for a minute?
yesterday i create code below.
-------------------------------------------------------------
--------------------------------
Code:
library(tidyverse)
library(rvest)
get_yahoo <- function(stock, type = "financials"){
if(type == "financials"){
url <- paste0("https://finance.yahoo.com/quote/", stock, "/financials?p=", stock)
} else if(type == "balance-sheet"){
url <- paste0("https://finance.yahoo.com/quote/", stock, "/balance-sheet?p=", stock)
} else if(type == "cash-flow"){
url <- paste0("https://finance.yahoo.com/quote/", stock, "/cash-flow?p=", stock)
} else if(type == "statistics"){
url <- paste0("https://finance.yahoo.com/quote/", stock, "/key-statistics?p=", stock)
# } else if(type == "analysis"){
# url <- paste0("https://finance.yahoo.com/quote/", stock, "/analysis?p=", stock)
} else {
stop("Please enter the type of data that you would like to scrape (e.g., \"statistics\")")
}
# Extract and transform data
x <- url %>%
read_html() %>%
html_table() %>%
map_df(bind_cols) %>%
# Transpose
t() %>%
as_tibble()
# Set first row as column names
colnames(x) <- x[1,]
# Remove first row
x <- x[-1,]
# Add stock name column
x$Stock_Name <- stock
return(x)
}
dd <- get_yahoo("CCL", "financials") ## it doesn't work.....!! :(
ff <- get_yahoo("CCL", "statistics") # it work
first. [ff <- get_yahoo("CCL", "statistics")]? it`s okay.
but [get_yahoo("CCL", "financials")] is doesn't work!!!
i need scraping yahoo finance financials data table.{financials/balance-sheet/cash-flow}
so I wonder what went wrong in the code above.
please reply.
i need help.