Skip to content

Instantly share code, notes, and snippets.

@daichan4649 daichan4649/main.gs
Created Jun 27, 2017

Embed
What would you like to do?
scrape subway status
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
You can’t perform that action at this time.