使用以下文档我一直试图从marketwatch.com刮掉一系列表
这是代码所代表的代码:
链接和xpath已包含在代码中:
url <- "http://www.marketwatch.com/investing/stock/IRS/profile"
valuation <- url %>%
html() %>%
html_nodes(xpath='//*[@id="maincontent"]/div[2]/div[1]') %>%
html_table()
valuation <- valuation[[1]]
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Warning message:
'html' is deprecated.
Use 'read_html' instead.
See help("Deprecated")
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我有两个数据集.两者都是xts对象.
> dput(head(all_data[,2:3]))
structure(c(0.00108166576527857, 0.00324149108589955, 0, 0, 0.00484652665589658,
0.00267952840300101, 0.00606980273141122, 0.00301659125188536,
0.00526315789473686, -0.00149588631264019, 0, -0.00299625468164799
), class = c("xts", "zoo"), .indexCLASS = c("POSIXct", "POSIXt"
), .indexTZ = "UTC", tclass = c("POSIXct", "POSIXt"), tzone = "UTC", index = structure(c(1453716060,
1453716120, 1453716180, 1453716240, 1453716300, 1453716360), tzone = "UTC", tclass = c("POSIXct",
"POSIXt")), .Dim = c(6L, 2L), .Dimnames = list(NULL, c("ClosePrice_AGL.1",
"ClosePrice_AMC")))
> dput(head(all_data[,1]))
structure(c(0.00108166576527857, 0.00324149108589955, 0, 0, 0.00484652665589658,
0.00267952840300101), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
"POSIXt"), .indexTZ = "UTC", …Run Code Online (Sandbox Code Playgroud) 我想知道是否可以使用相对简单的 R 代码提取数据并将数据输入到附加到电子邮件的文本文件中,而无需让我的电脑保持开启状态。
我这里有一个网络抓取代码,使用:
library(XML)
library(stringr)
Run Code Online (Sandbox Code Playgroud)
抓取一些我想每天保存的网络数据..
将其放在每 24 小时运行一次的循环中相对容易,但我不想在运行时保持我的 PC 开启或无法使用 R 环境。
我有什么选择?
我有流动的文本字符串:
string <- "['CBOE SHORT-TERM VIX FUTURE DEC 2016', 81.64],\n\n ['CBOE SHORT-TERM VIX FUTURE JAN 2017', 18.36]"
Run Code Online (Sandbox Code Playgroud)
是否有一种从文本中提取数字元素的简单方法,而不必使用:
string_table <- strsplit(string, " ")
Run Code Online (Sandbox Code Playgroud)
然后选择第n个元素并继续strsplit直到我拥有我需要的东西.
结果应该是:
result <- c(2016, 81, 64, 2017, 18, 36)
Run Code Online (Sandbox Code Playgroud)
谢谢.