Skip to content

Instantly share code, notes, and snippets.

@matsuhisa
Created September 23, 2015 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsuhisa/db52edb5e72a1abb8d4e to your computer and use it in GitHub Desktop.
Save matsuhisa/db52edb5e72a1abb8d4e to your computer and use it in GitHub Desktop.
var Lwp, urls;
var urls = [
'http://qiita.com/',
'https://github.com/',
'http://www.yahoo.co.jp/'
];
Lwp = function(urls, callbackPerUrl, callbackFinal){
var next, page, retrieve, urlIndex, webpage;
urlIndex = 0;
webpage = require("webpage");
page = null;
next = function(status, url){
page.close();
callbackPerUrl(status, url);
return retrieve();
};
retrieve = function() {
var url;
if(urls.length > 0){
url = urls.shift();
urlIndex++;
page = webpage.create();
page.open(url, function(status) {
if (status === "success") {
page.render('list_' + urlIndex + '.png');
next(status, url);
}else{
next(status, url);
}
});
}else {
callbackFinal();
}
}
retrieve();
};
Lwp(urls,
function(status, url){
console.log(url);
},
function(){
phantom.exit();
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment