我正在尝试从Google地图网址中提取文字数据(例如经销商类型,经销商名称)。我为此写了以下代码:
library(RSelenium)
library(XML)
library(xlsx)
test<-read.xlsx("C:\\Selenium_Tool\\Segmentaion_Files\\test.xlsx",1)
test$addr<-paste(test$CUST_ADDRESS,test$CUST_CITY, test$CUST_STATE,sep =
",")
test$URL<-paste("https://www.google.co.in/maps/place/",test$addr)
View(test)
rd<-rsDriver(port = 4567L, browser = c("chrome", "firefox", "phantomjs",
"internet explorer"), version = "latest", chromever = "latest", geckover =
"latest", iedrver = NULL, phantomver = "2.1.1", verbose = TRUE, check =
TRUE)
remDr <- rd[["client"]]
for(i in 1:length(test$CUST_ID)) {
remDr$navigate(test$URL[i])
webElem<-remDr$findElements(using = 'class','section-listbox')
elem<-webElem[1]
class(elem)
test$result[i]<-elem$getElementText()[[1]]
}
remDr$close()
rd[["server"]]$stop()
在test.xlsx中,我的谷歌地图网址很少。当我尝试为100个网址运行此代码时,它运行正常,但是当我运行此代码超过100个网址时,它会给我错误说明: webElem [[1]]中的错误:下标超出范围
请帮我解决这个问题。