我无法使用RSelenium抓取多个URL的内容。如果我分别抓取每个网页,将会得到预期的结果。但是,当尝试使用循环时,我没有得到结果
library(RSelenium)
#Setting the remote browser
remDr <- RSelenium::remoteDriver(remoteServerAddr = "192.168.99.100",
port = 4444L,
browserName = "chrome")
remDr$open()
links <- c('https://www.lasillavacia.com/node/68077', 'https://www.lasillavacia.com/node/56774', 'https://www.lasillavacia.com/node/57833')
test_silla <- data.frame()
for(i in 1:(length(links))) {
remDr$navigate(paste0(links[[i]]))
Sys.sleep(1)
print(i)
content_test <- remDr$findElements(using = "css selector", value = ".article-date")
content_test2 <- data.frame(url = unlist(sapply(content_test, function(x){x$getElementText()})))
Sys.sleep(1)
test_silla <- rbind(test_silla, content_test2)
}
url_test <- 'https://www.lasillavacia.com/node/68077'
remDr$navigate(url_test)
content_test <- remDr$findElements(using = "css selector", value = '.article-date')
content_test <- sapply(url_test, function(x){x$getElementText()})
我使用类似的代码使用RSelenium抓取了另一个网站,并且它起作用了。有人可以帮忙吗?谢谢!