Giving consent to cookies using rvest

白昼怎懂夜的黑 提交于 2021-01-28 11:25:22

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/65374044/giving-consent-to-cookies-using-rvest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!