Skip to content

Instantly share code, notes, and snippets.

@shiawuen
Created October 16, 2012 16:36
Show Gist options
  • Save shiawuen/3900412 to your computer and use it in GitHub Desktop.
Save shiawuen/3900412 to your computer and use it in GitHub Desktop.
var page = require('webpage').create();
var system = require('system');
page.open(system.args[1], function(){
var ret = page.evaluate(function(){
var each = [].forEach;
var residency_code = {
"Eligible for in-district tuition" : 'in_state'
, "Eligible for in-state tuition" : 'in_state'
, "Eligible for out-of-state tuition" : 'out_of_state'
, "Eligible for resident tuition" : 'in_state'
, "Eligible for in-district tuition" : 'in_state'
, "Eligible for non-resident tuition" : 'out_of_state'
};
var living_status_code = {
"On-campus (in a residence hall, dormitory, or on-campus apartment)" : 'on_campus'
, "Living on my own or with a roommate" : 'off_campus_without_family'
, "Living with my parents or other family members" : 'off_campus_with_family'
};
var total = window.POA_Total;
var residency = [];
var living = [];
each.call(
document.querySelectorAll('[name=rb_residencystatus]')
, function(elem, idx){
residency[ idx ] = residency_code[ elem.getAttribute('title') ];
}
);
each.call(
document.querySelectorAll('[name=rb_livingstatus]')
, function(elem, idx){
living[ idx ] = living_status_code[ elem.getAttribute('title') ];
}
);
var results = {}, k, v;
for (var r = residency.length; r--; ) {
for (var l = living.length, ll = l; l--; ) {
for (var t=total.length, tl = t; t--; ) {
k = ['POA_Total', residency[r], living[l]].join(':');
v = total[r * ll * l];
results[k] = v;
}
}
}
return JSON.stringify(results);
})
console.log(ret);
page.release();
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment