docparse-scraper-nst
Version:
Node Zombie based scraper to scrape bills from the NStar (supplier code "NST)" website
35 lines (34 loc) • 1.13 kB
JavaScript
var inspect = require('eyespect').inspector();
module.exports = function(data, cb) {
var message;
if (!data.bro) {
return cb('"bro" field missing from data');
}
var bro = data.bro;
inspect('getting account numbers');
var dropdown = bro.querySelector('select[name="accountNumber"]');
if (!dropdown) {
message = 'dropdown not found when getting number of accounts on the account homepage';
inspect(message);
return cb(message);
}
var options = bro.querySelectorAll('select[name=accountNumber] option');
if (!options) {
message = 'options not found when getting number of accounts on the account homepage';
inspect(message);
return cb(message);
}
var accountNumbers = options.map(function (option) {
var value = option.getAttribute('value');
return value;
});
var accountNames = options.map(function (option) {
return option.innerHTML;
});
options.sort(function (a, b) {
return a.getAttribute('value')-b.getAttribute('value');
});
var length = accountNumbers.length;
inspect(length,'number of accounts on homepage');
return cb(null, accountNumbers);
}