Created
September 23, 2015 10:04
-
-
Save matsuhisa/db52edb5e72a1abb8d4e to your computer and use it in GitHub Desktop.
複数の url を順番に処理していく https://github.com/ariya/phantomjs/blob/master/examples/render_multi_url.js
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 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