使用 rvest 同意 cookie [英] Giving consent to cookies using rvest

查看:84
本文介绍了使用 rvest 同意 cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题,令人惊讶的是,我在 SO 上找不到任何答案:您如何同意网站上的 cookie.

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

我运行的代码如下:

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)

这给出了一个空的 data.frame,我怀疑这是因为网站要求同意跟踪 cookie.如何使用 rvest 同意此类 cookie?

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?

推荐答案

类似于这个问题 我已经回答了,我会给你从表中获取数据的代码:

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

这篇关于使用 rvest 同意 cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆