-
-
Save donfanning/3edee3dc7ba49d6c1df937df83c46b7b to your computer and use it in GitHub Desktop.
Parallel crawler example using PhantomJS and Aysnc.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
// usage: phantomjs async-phantom.js | |
var async = require('async'), | |
links = [ | |
"http://google.com", | |
"http://yahoo.com", | |
"http://duckduckgo.com", | |
"http://bing.com", | |
]; | |
function crawler(url, callback) { | |
var page = require('webpage').create(); | |
page.open(url, function (status) { | |
console.log( page.evaluate(function(){ return document.title }) ); | |
page.close(); | |
callback.apply(); | |
}); | |
} | |
async.each(links, crawler, function (err) { | |
if (err) console.log(err); | |
phantom.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment