I'm trying to calculate the flight time between every country in hopes to create parameters for a fraud prevention tool I'm scoping out.
The website url I'm working with is https://www.travelmath.com/flying-time/from/Canada/to/Germany
The third column I have is replacing the two country references with all the possible combinations.
I'm trying to use RVEST with a loop to do this but keep receiving various errors. I've looked on stack to try and fit other solutions to my problem but have run into numerous issues. Lastly I'm trying to create a loop that doesn't blast the website I'm querying with 55225 requests in a short window.
Here's the most recent solution I've tried but I keep getting the following errors in repetition
I've tried re-arranging my data frame and handling the replacement of the origin and destination.
I've tried using Rselenium to do this but ran into other issues as well.
I've tried re-formatting other solutions to similar problems but still receive errors.
tables <- list()
index <- 1
for (i in CountryPairs){
try(
{
url <- paste0("https://www.travelmath.com/flying-time/from/",i)
table <- url %>%
read_html()%>%
html_nodes("#flyingtime")
tables[index] <- table
index <- index +1
}
)
}
df<-do.call("rbind",tables)
Error in open.connection(x, "rb") : HTTP error 400.
Error in tables[index] <- table : replacement has length zero