R rvest 检索空表 [英] R rvest retrieve empty table

查看:28
本文介绍了R rvest 检索空表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试两种策略来从网络表中获取数据:

I'm trying two strategies to get data from a web table:

library(tidyverse)  
library(rvest)                        

webpage <- read_html('https://markets.cboe.com/us/equities/market_statistics/book/')
data <- html_table(webpage, fill=TRUE)
data[[2]]

''

library("httr")
library("XML")

URL <- 'https://markets.cboe.com/us/equities/market_statistics/book/'
temp <- tempfile(fileext = ".html")
GET(url = URL, user_agent("Mozilla/5.0"), write_disk(temp))

df <- readHTMLTable(temp)
df <- df[[2]]

他们都返回一个空表.

推荐答案

从刷新 URL 时可以在网络选项卡中找到的另一个端点动态检索值.您需要为服务器添加一个引用标头,以返回包含表数据的 json.

Values are retrieved dynamically from another endpoint you can find in the network tab when refreshing your url. You need to add a referer header for the server to return json containing the table data.

library(httr)

headers = c('Referer'='https://markets.cboe.com/us/equities/market_statistics/book/')
d <- content(httr::GET('https://markets.cboe.com/json/bzx/book/FIT', httr::add_headers(.headers=headers)))
print(d$data)

这篇关于R rvest 检索空表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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