pApaAPPApapapa
pApaAPPApapapa

Reputation: 385

Giving consent to cookies using rvest

Simple question, which I surprisingly couldn't find any answer to on SO: how can you give consent for cookies on websites.

I run code like:

require(rvest)
finances <- "https://finance.yahoo.com/quote/MSFT/financials?p=MSFT&_guc_consent_skip=1608408673"
finances <- read_html(finances)
finances <- html_table(finances,header = TRUE)

This give a empty data.frame, and I suspect it is because the websites asks for consent for tracking cookies. How does one give consent to such cookies using rvest?

Upvotes: 1

Views: 205

Answers (1)

xwhitelight
xwhitelight

Reputation: 1579

Similar to this question that I've answered, I'll give you the code to get the data from the table:

library(rvest)
library(V8)
pg <- read_html("https://finance.yahoo.com/quote/MSFT/financials?p=MSFT&_guc_consent_skip=1608408673")
js <- pg %>% html_node(xpath = "//script[contains(., 'root.App.main')]") %>% html_text()
ct <- new_context()
ct$eval(js)
data <- ct$get("App")
incomeStatementHistory <- data$main$context$dispatcher$stores$QuoteSummaryStore$incomeStatementHistory
incomeStatementHistoryQuarterly <- data$main$context$dispatcher$stores$QuoteSummaryStore$incomeStatementHistoryQuarterly

Upvotes: 2

Related Questions