【发布时间】:2019-01-07 02:01:09
【问题描述】:
我尝试使用 R 和包 httr 和 rvest 自动从本网站 https://www.finanssivalvonta.fi/en/capital-markets/issuers-and-investors/Managers-transactions/shortselling/ 的 csv 链接导出数据。我尝试了以下代码但没有成功,我不明白我的错误。
访问网站并使用 chrome 查看已完成的 POST 时,我看到以下链接 https://www.finanssivalvonta.fi/api/shortselling/datatable/current/export。但是当在 R 中使用相同的链接时,我的状态代码为 500。我是否必须从 chrome POST 复制所有标题/正文?如果是,我该怎么做?
library(httr)
library(rvest)
res <- POST("https://www.finanssivalvonta.fi/api/shortselling/datatable/current/export")
res$status_code
# 500
我也尝试使用以下代码直接导出表格,但网页似乎没有完成加载
url <- html_session("https://www.finanssivalvonta.fi/en/capital-markets/issuers-and-investors/Managers-transactions/shortselling/")
url %>% html_nodes("table") %>% .[[1]] %>% html_table(fill=T)
# Error in matrix(NA_character_, nrow = n, ncol = maxp) :
# invalid 'ncol' value (too large or NA)
# In addition: Warning messages:
# 1: In max(p) : no non-missing arguments to max; returning -Inf
# 2: In matrix(NA_character_, nrow = n, ncol = maxp) :
# NAs introduced by coercion to integer range
非常感谢
【问题讨论】: