Skip to content

Instantly share code, notes, and snippets.

@TerasawaShuhei
Forked from ahomu/shots_from_listed_urls.js
Last active December 17, 2015 14:09
Show Gist options
  • Save TerasawaShuhei/5622708 to your computer and use it in GitHub Desktop.
Save TerasawaShuhei/5622708 to your computer and use it in GitHub Desktop.
スクショいっぱい撮るとき。require phantomjs >1.7, async.js >0.2.7
var PARALLEL_LIMIT = 3;
var Page = require('webpage');
var async = require('/Users/shuuheyhey/Sites/async.js');
var i = 0, iz;
var urls = [
"http://css.studiomohawk.com",
"http://inkdesign.jp",
"http://t32k.me/mol",
"http://havelog.ayumusato.com",
"http://aho.mu"
].map(function(url) {
return function(done) {
var page = Page.create();
page.viewportSize = {
width: 1024,
height: 768
};
i++;
console.log(i + '/' + iz + '...');
page.onLoadFinished = function() {
page.render('./shots/'+url.replace(/https?:\/\//, '').replace(/\//g, '_')+'.png');
page.close();
done(null, '✓ ' + url);
};
page.open(url);
};
});
iz = urls.length;
console.log('\ntotal ' + iz + ' urls. start page capturing…\n');
async.parallelLimit(urls, PARALLEL_LIMIT, function(err, results) {
console.log('\n' + results.join('\n'));
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment