Rrvest检索空表

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

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]]

他们两个都返回一个空表。

wangjie5555 回答:Rrvest检索空表

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

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)
本文链接:https://www.f2er.com/3169999.html

大家都在问