首页 > 解决方案 > 从 chrome 下载数据的代码问题

问题描述

我正在尝试从这里执行代码:https ://rpubs.com/mbadros/sp500history 但我是 R 的新手。我被困在那个街区:

library(rJava)
library(RSelenium)

base_url <- 'https://www.ishares.com/us/products/239726/ishares-core-sp-500-etf'

rD <- rsDriver(port = 4839L, browser = c("chrome"), chromever="84.0.4147.30")
remDr <- rD$client
remDr$navigate(base_url)

test <- remDr$findElement(using = 'css selector', '#holdingsTabs li a[href*="All"]')
test$clickElement()

option_list <- remDr$findElement(using = 'css selector',
                                 '#holdingsTabs #tabsAll .date-dropdown')$selectTag()

get_top_holdings <- function(x) {
  option_list$elements[[x]]$clickElement()
  remDr$findElement(using = 'css selector', '.holdings .icon-xls-export')$clickElement()
}

lapply(1:length(option_list$value), get_top_holdings)

我收到一个错误:

Error in option_list$elements[[x]]$clickElement(): attempt to apply non-function

试图用谷歌解决问题,但找不到解决方案。

标签: rrselenium

解决方案


推荐阅读