I am trying to scrape all bills from two pages on the website of the French lower chamber of parliament. The pages cover 2002-2012 and represent less than 1,000 bills each.
For this, I scrape with getURL
through this loop:
b <- "http://www.assemblee-nationale.fr" # base
l <- c("12","13") # legislature id
lapply(l, FUN = function(x) {
print(data <- paste(b, x, "documents/index-dossier.asp", sep = "/"))
# scrape
data <- getURL(data); data <- readLines(tc <- textConnection(data)); close(tc)
data <- unlist(str_extract_all(data, "dossiers/[[:alnum:]_-]+.asp"))
data <- paste(b, x, data, sep = "/")
data <- getURL(data)
write.table(data,file=n <- paste("raw_an",x,".txt",sep="")); str(n)
})
Is there any way to optimise the getURL()
function here? I cannot seem to use concurrent downloading by passing the async=TRUE
option, which gives me the same error every time:
Error in function (type, msg, asError = TRUE) :
Failed to connect to 0.0.0.12: No route to host
Any ideas? Thanks!