Created
January 13, 2016 14:14
-
-
Save bbarao/a6bc682c1fe57dd2ae0a to your computer and use it in GitHub Desktop.
Phantom.js Bulk Screenshot
This file contains 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
#!/bin/bash | |
for i in $(cat hosts); do | |
for s in http https; do | |
HOST=$s://$i | |
echo " > $HOST" | |
phantomjs --proxy=localhost:8080 --ssl-protocol=any --ignore-ssl-errors=true screenshot.js "$HOST" | |
done | |
done |
This file contains 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
var GLOBAL_TIMEOUT = 30; | |
var RESOURCE_TIMEOUT = 10; | |
var system = require('system'); | |
var address = system.args[1]; | |
var page = require('webpage').create(); | |
var redirectURL = null; | |
page.clipRect = { | |
top: 0, | |
left: 0, | |
width: 1920, | |
height: 1200 | |
}; | |
page.viewportSize = {width: 1920, height: 1200}; | |
page.settings.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36"; | |
page.settings.resourceTimeout = Math.round(RESOURCE_TIMEOUT*1000); | |
page.customHeaders = { | |
"Accept-Language": "en,*" | |
}; | |
try{ | |
page.open(address, function (status) { | |
if (status !== 'success') { | |
console.log('Unable to load the address! Status = '+status); | |
phantom.exit(); | |
} else { | |
window.setTimeout(function () { | |
/*bgColor = window.getComputedStyle(document.body, null).backgroundColor; | |
if (bgColor == "rgba(0, 0, 0, 0)") { | |
page.evaluate(function() { | |
document.body.bgColor = 'white'; | |
}); | |
}*/ | |
page.render("images/" + Date.now() + "_" + address.replace(/\//g,'_').replace(/:/g,'_') + ".png"); | |
phantom.exit(); | |
}, 1000); | |
} | |
}); | |
} finally{ | |
setTimeout(function() { | |
console.log("Max execution time " + GLOBAL_TIMEOUT + " seconds exceeded"); | |
phantom.exit(1); | |
}, Math.round(GLOBAL_TIMEOUT*1000)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment