Created
January 15, 2016 19:28
-
-
Save martinjacobs/ae71dcf446fc2c5613e2 to your computer and use it in GitHub Desktop.
Site crawler
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 phantom = require('phantom'); | |
var Crawler = require("simplecrawler"); | |
var mycrawler = Crawler.crawl("http://www.example.com/"); | |
mycrawler.maxDepth = 3; | |
mycrawler.interval = 500; | |
mycrawler.addFetchCondition(function(parsedURL) { | |
if (parsedURL.path.match(/\.(css|jpg|pdf|docx|js|png|ico)/i)) { | |
// console.log("Ignored ",parsedURL.path); | |
return false; | |
} | |
return true; | |
}); | |
mycrawler.on("fetchcomplete", function(queueItem) { | |
//console.log("Completed fetching resource:", queueItem.url); | |
var crawlwait = this.wait(); | |
phantom.create(function(ph) { | |
ph.createPage(function(page) { | |
page.open(String(queueItem.url), function(status) { | |
console.log("opened " + queueItem.url, status); | |
console.log("rendering " + queueItem.path); | |
page.render("item" + queueItem.path.replace(/\//g, "_") + '.png'); | |
console.log("finished rendering " + queueItem.path); | |
crawlwait(); | |
ph.exit(); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment