Skip to content

Instantly share code, notes, and snippets.

@seabre
Created October 11, 2012 18:44
Show Gist options
  • Save seabre/3874642 to your computer and use it in GitHub Desktop.
Save seabre/3874642 to your computer and use it in GitHub Desktop.
Pagespeed crawler for PhantomJS
var address, sitemap, system;
sitemap = require('webpage').create();
system = require('system');
if (system.args.length === 1) {
console.log('Usage: pagespeed.js <some DOMAIN>');
phantom.exit(1);
} else {
address = system.args[1];
sitemap.open("http://saidigital.co/sitemap.xml", function(status) {
var i, process, urls, visit, _i, _len;
if (status === "success") {
urls = sitemap.evaluate((function() {
return document.getElementsByTagName("loc");
}));
sitemap.release();
for (_i = 0, _len = urls.length; _i < _len; _i++) {
i = urls[_i];
console.log(i);
}
visit = function(url, callback) {
var page, t;
console.log("Able to get to this callback: " + url);
t = Date.now();
page = require('webpage').create();
return page.open(url, function(status) {
console.log("Got to the page open callback?");
if (status === 'fail') {
"Looks like URL doesn't exist?";
} else {
t = Date.now() - t;
console.log("Loading time for " + url + ": " + t);
}
page.release();
return callback.apply();
});
};
process = function() {
var url;
if (urls.length > 0) {
url = str(urls[0].textContent);
console.log(url);
urls.splice(0, 1);
return visit(url, process);
} else {
return phantom.exit();
}
};
process();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment