Skip to content

Instantly share code, notes, and snippets.

@alvincyh
Last active March 18, 2018 08:43
Show Gist options
  • Save alvincyh/8dbb0bb114e3c8cf2fa733c559f48bd9 to your computer and use it in GitHub Desktop.
Save alvincyh/8dbb0bb114e3c8cf2fa733c559f48bd9 to your computer and use it in GitHub Desktop.
Scrap TransitLink for Singapore MRT / LRT Station to Station Travel Travel Time
# Estimated travel time does NOT include waiting time
library(httr)
library(stringr)
getTravelTime <- function(start_code, stop_code){
params <- list(
mrtcode_start = start_code,
mrtcode_end = stop_code,
action = "script.cgi",
submit = "return isFilled('formmrt')"
)
res <- POST("https://www.transitlink.com.sg/eservice/eguide/rail_info.php", body = params, encode = "form", verbose())
str <- content(res, "text", "UTF-8")
res <- str_match(str, "<td rowspan=\"4\">(.*?)</td> ")
return (res[,2])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment