使用 R 的 htmltab 时出错:`*tmp*`[[index]] 中的错误:下标越界
error using R's htmltab: Error in `*tmp*`[[index]] : subscript out of bounds
正在尝试使用
从 Google Finance 下载 INX
x <- htmltab(doc = "https://www.google.com/finance/historical?q=INDEXSP%3A.INX&ei=Qu-TWOn-AtW1mQGQ06WYCQ")
它给出了这个错误:
Error in `*tmp*`[[index]] : subscript out of bounds
我无法让 htmltab
工作,但您可以使用 library(rvest)
解析网页,并指定 table[= 的特定 xpath
14=]
library(rvest)
url <- "https://www.google.com/finance/historical?q=INDEXSP%3A.INX&ei=Qu-TWOn-AtW1mQGQ06WYCQ"
read_html(url) %>%
html_node(xpath = "//*[@class='gf-table historical_price']") %>%
html_table()
# Date Open High Low Close Volume
# 1 Feb 2, 2017 2,276.69 2,283.97 2,271.65 2,280.85 2,321,960,100
# 2 Feb 1, 2017 2,285.59 2,289.14 2,272.44 2,279.55 2,478,979,663
# 3 Jan 31, 2017 2,274.02 2,279.09 2,267.21 2,278.87 2,555,320,206
# 4 Jan 30, 2017 2,286.01 2,286.01 2,268.04 2,280.90 2,108,083,825
# ...
正在尝试使用
从 Google Finance 下载 INXx <- htmltab(doc = "https://www.google.com/finance/historical?q=INDEXSP%3A.INX&ei=Qu-TWOn-AtW1mQGQ06WYCQ")
它给出了这个错误:
Error in `*tmp*`[[index]] : subscript out of bounds
我无法让 htmltab
工作,但您可以使用 library(rvest)
解析网页,并指定 table[= 的特定 xpath
14=]
library(rvest)
url <- "https://www.google.com/finance/historical?q=INDEXSP%3A.INX&ei=Qu-TWOn-AtW1mQGQ06WYCQ"
read_html(url) %>%
html_node(xpath = "//*[@class='gf-table historical_price']") %>%
html_table()
# Date Open High Low Close Volume
# 1 Feb 2, 2017 2,276.69 2,283.97 2,271.65 2,280.85 2,321,960,100
# 2 Feb 1, 2017 2,285.59 2,289.14 2,272.44 2,279.55 2,478,979,663
# 3 Jan 31, 2017 2,274.02 2,279.09 2,267.21 2,278.87 2,555,320,206
# 4 Jan 30, 2017 2,286.01 2,286.01 2,268.04 2,280.90 2,108,083,825
# ...