Skip to content

Instantly share code, notes, and snippets.

@howdoicomputer
Created April 25, 2015 21:51
Show Gist options
  • Save howdoicomputer/aabc0f5589a51839fc6c to your computer and use it in GitHub Desktop.
Save howdoicomputer/aabc0f5589a51839fc6c to your computer and use it in GitHub Desktop.
/**
* 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