【发布时间】:2021-02-04 22:14:10
【问题描述】:
我正在尝试从网上抓取一张表格(此处为 https://www.cryptoslam.io/nba-top-shot/marketplace)。
我一直在研究如何做到这一点,并且似乎使用库 rvest 和 html_table() 函数最接近。事实上,我可以使用代码从这里https://en.wikipedia.org/wiki/Brazil_national_football_team 下载“FIFA 世界杯记录”表
webpage_url <- "https://en.wikipedia.org/wiki/Brazil_national_football_team"
webpage <- xml2::read_html(webpage_url)
tbls <- html_nodes(webpage, "table")
head(tbls)
tbls_ls <- webpage %>%
html_nodes("table") %>%
.[[6]] %>%
html_table(fill = TRUE)
请注意,我已加载库 library(xml2)、library(rvest)。然后我在这里使用基本相同的代码:
webpage_url <- "https://www.cryptoslam.io/nba-top-shot/marketplace"
webpage <- xml2::read_html(webpage_url)
tbls <- html_nodes(webpage, "table")
head(tbls)
tbls_ls <- webpage %>%
html_nodes("table") %>%
.[[1]] %>%
html_table(fill = TRUE)
但出现错误
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
我无法在其他任何地方找到有关此错误的任何讨论。两个表之间的不同之处在于第二个表中存在 thead 标记,该标记不起作用。我对 html 的了解非常有限,因此我可能会遗漏表格实现之间的一些其他重要差异。
【问题讨论】:
标签: javascript html r rvest