Created
June 27, 2017 00:02
-
-
Save daichan4649/99e055de82a52888dd2265e6356e2716 to your computer and use it in GitHub Desktop.
scrape subway status
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
var URL_SUBWAY = "http://subway.city.fukuoka.lg.jp/status/"; | |
var REGEXP_STATUS = /<div class=\"statusNews\">(.*)<\/div>/gi; | |
function doGet() { | |
var status = scrapeSubwayStatus(); | |
Logger.log(status); | |
var json = {}; | |
json['status'] = status; | |
json['url'] = URL_SUBWAY; | |
Logger.log(json); | |
return ContentService.createTextOutput(JSON.stringify(json)).setMimeType(ContentService.MimeType.JSON); | |
} | |
function scrapeSubwayStatus() { | |
var response = UrlFetchApp.fetch(URL_SUBWAY); | |
var elements = response.getContentText().match(REGEXP_STATUS); | |
if(elements == null || elements.length == 0) { | |
return "なにかが起きている"; | |
} | |
// 1件目前提 | |
var status = elements[0]; | |
status = status.replace(/<div class=\"statusNews\">/gi, ""); | |
status = status.replace(/<\/div>/gi, ""); | |
return status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment