/ / R: Introducción de intervalos de tiempo al raspar - r

R: Introducción de intervalos de tiempo al raspar - r

Estoy tratando de raspar algunos sitios web usando"RSelenium". Sin embargo, parece que los sitios web detectan mi intento de raspar. ¿Sería posible introducir algunos intervalos de tiempo entre cada raspadura? Mi codigo es este

Library("XML")
library("RSelenium")
checkForServer() # search for and download Selenium Server java binary.  Only need to run once.
startServer() # run Selenium Server binary
remDr <- remoteDriver(browserName="firefox", port=4444) # instantiate remote driver to connect to Selenium Server
remDr$open(silent=T) # open web browser

page_sub = read.csv("indigogo_edu_us.csv")

url_list = as.vector(page_sub$full_url[1:3])

scrape = function(url_list){

remDr$navigate(url_list) # navigates to webpage

elem <- remDr$findElement(using="class", value="i-description")
elemtxt <- elem$getElementAttribute("outerHTML")[[1]]
elemxml <- htmlTreeParse(elemtxt, useInternalNodes=T)

fundList <- unlist(xpathApply(elemxml, "//input[@title]", xmlGetAttr, "title")) # parses out just the fund name and ticker using XPath
page = as.data.frame(xpathSApply(  elemxml,"//div[@class="i-description"]", xmlValue, encoding="utf-8"))
names(page)[1] = "description"
}
cc = lapply(url_list, scrape)

Respuestas

2 para la respuesta № 1

Por supuesto, Sys.sleep. También puedes usar un generador de números aleatorios para que parezca aleatorio.

Algo a lo largo de las líneas de

Sys.sleep(runif(1, min = 3, max = 11))