Skip to content

Instantly share code, notes, and snippets.

@cjroebuck
Created May 14, 2013 23:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjroebuck/5580502 to your computer and use it in GitHub Desktop.
Save cjroebuck/5580502 to your computer and use it in GitHub Desktop.
node multipleRequests.js
http://facebook.com: spooky initialised
http://news.ycombinator.com: spooky initialised
http://bbc.co.uk: spooky initialised
http://daringfireball.net: spooky initialised
http://instagram.com: spooky initialised
http://path.com: spooky initialised
http://facebook.com: Callback with saved file: /Users/cjroebuck/Dev/http:/news.ycombinator.com.png
http://news.ycombinator.com: Callback with saved file: /Users/cjroebuck/Dev/http:/news.ycombinator.com.png
http://bbc.co.uk: Callback with saved file: /Users/cjroebuck/Dev/http:/news.ycombinator.com.png
http://daringfireball.net: Callback with saved file: /Users/cjroebuck/Dev/http:/news.ycombinator.com.png
http://instagram.com: Callback with saved file: /Users/cjroebuck/Dev/http:/news.ycombinator.com.png
http://path.com: Callback with saved file: /Users/cjroebuck/Dev/http:/news.ycombinator.com.png
Done, Fin - The End...
http://facebook.com: Callback with saved file: /Users/cjroebuck/Dev/http:/facebook.com.png
http://facebook.com: Callback with saved file: /Users/cjroebuck/Dev/http:/daringfireball.net.png
http://facebook.com: Callback with saved file: /Users/cjroebuck/Dev/http:/bbc.co.uk.png
http://facebook.com: Callback with saved file: /Users/cjroebuck/Dev/http:/path.com.png
http://facebook.com: Callback with saved file: /Users/cjroebuck/Dev/http:/instagram.com.png
var Spooky, async, takeScreenshot, urls, wrapScreenshotFn;
async = require('async');
Spooky = require('spooky');
urls = ['http://bbc.co.uk', 'http://news.ycombinator.com', 'http://instagram.com', 'http://path.com', 'http://facebook.com', 'http://daringfireball.net'];
takeScreenshot = function(url, cb) {
var spooky = new Spooky({
child: {
"web-security": false,
"ignore-ssl-errors": true
},
casper: {
logLevel: "info",
verbose: false,
timeout: 30000,
stepTimeout: 15000
}
}, function(err) {
var e;
if (err) {
e = new Error(url + ": Failed to initialize SpookyJS");
e.details = err;
throw e;
}
console.log(url + ': spooky initialised');
spooky.on('capture.saved', function(targetFile) {
cb(null, targetFile);
});
spooky.on('error', function(e) {
console.error("error rendering:");
console.error(e);
});
spooky.on('step.timeout', function() {
console.log('we have reached the step timeout limit (' + url + ')');
});
spooky.start();
spooky.open(url);
spooky.then([
{
renderName: url + '.png',
width: 1280,
height: 1024,
url: url,
delay: 100
}, function() {
this.viewport(width, height);
this.capture(renderName, {
top: 0,
left: 0,
width: width,
height: height
});
}
]);
spooky.run();
});
};
wrapScreenshotFn = function(url, cb) {
takeScreenshot(url, function(err, target) {
console.log(url + ': Callback with saved file: ' + target);
cb(err);
});
};
async.each(urls, wrapScreenshotFn, function(err) {
console.log('Done, Fin - The End...');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment