Last active
March 18, 2018 08:43
-
-
Save alvincyh/8dbb0bb114e3c8cf2fa733c559f48bd9 to your computer and use it in GitHub Desktop.
Scrap TransitLink for Singapore MRT / LRT Station to Station Travel Travel Time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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