Created
April 25, 2015 21:51
-
-
Save howdoicomputer/aabc0f5589a51839fc6c to your computer and use it in GitHub Desktop.
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
/** | |
* Fetch a list of station IDs | |
* | |
* @param {String} url | |
* @return {Array} ids | |
*/ | |
function fetchStationIDList(url, callback) { | |
request(url, function(error, response, html) { | |
if (!error && response.code == 200) { | |
var $ = cheerio.load(html); | |
var table = $('#main_content table td'); | |
var regex = /^[A-Z]{3}$/; | |
var ids = []; | |
table.each( function() { | |
var td = _.trim($(this).text()); | |
if (td.match(regex)) { | |
ids.push(td); | |
} | |
}); | |
console.log('hello'); | |
callback(ids); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment