Skip to content

Instantly share code, notes, and snippets.

@AstroCB
Created January 12, 2017 06:29
Show Gist options
  • Save AstroCB/344f61903e6d05f797b6578eb7390995 to your computer and use it in GitHub Desktop.
Save AstroCB/344f61903e6d05f797b6578eb7390995 to your computer and use it in GitHub Desktop.
An example PhantomJS script for pulling class data from a schedule webpage.
const page = require("webpage").create();
page.open("https://classes.cornell.edu/shared/schedule/SP17/f2447538c565d8b0821840d825a50430", function(status) {
console.log("Loaded with status " + status);
if (status == "success") {
var doc = page.evaluate(function(parse) {
parse(document);
}, parse);
phantom.exit();
}
});
page.onConsoleMessage = function(msg) {
console.log(msg);
};
function parse(document) {
var days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
var x = document.getElementsByClassName("fc-event-container");
for (var i = 0; i < x.length; i++) {
var tempCol = x[i];
if ((' ' + tempCol.className + ' ').indexOf(' ' + "fc-helper-container" + ' ') == -1) {
var y = x[i].getElementsByClassName("fc-content");
console.log(days.shift());
for (var j = 0; j < y.length; j++) {
var text = y[j].innerText;
console.log(text);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment