Created
January 12, 2017 06:29
-
-
Save AstroCB/344f61903e6d05f797b6578eb7390995 to your computer and use it in GitHub Desktop.
An example PhantomJS script for pulling class data from a schedule webpage.
This file contains hidden or 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
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