I have webscraped the URLs corresponding to different tables from a webpage (using RSelenium). These URLs I stored in an object called 'URL'. Now I want in a next step to write away each of the table in text format to the directory I specified in the loop below. But for some reason the loop stops after 5 iterations and I cannot figure out why? Any ideas or hints?
for (i in 1:length(URL)){
remDr$navigate(URL[i])
date <- Sys.Date()
file <- paste("./WebScraping Connecting/Connecting_","_", date, ".txt", sep="")
y2 <- remDr$getPageSource()
y2 <- unlist(y2)
y3 <- readHTMLTable(y2, header=TRUE)
l <- unlist(lapply(y3[[1]], paste, collapse=" "))
for (j in 2:length(y3)){
l1 <- unlist(lapply(y3[[j]], paste, collapse=" "))
if (!is.null(l1)){
l <- rbind(l, l1)
}
}
write(as.vector(l), file=file)
Update: Sometimes the loop stops even after 3 iterations. It seems to work fine if I go through the loop by hand. However, I do get this warning message:
In rbind(l, l1) :
number of columns of result is not a multiple of vector length (arg 1)