Last active
August 29, 2015 14:06
-
-
Save cheeming/d2b732052eaa07203fae to your computer and use it in GitHub Desktop.
Download current HackerNews articles into PDF (CasperJS)
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
// tested with casperjs v1.1.0-beta3 and phantomjs v1.9.7 | |
var casper = require('casper').create({ | |
viewportSize: {width: 1024, height: 768} | |
}); | |
casper.start('https://news.ycombinator.com/', function() { | |
this.capture('hackernews-main.pdf'); | |
var links = this.evaluate(function() { | |
var l = document.querySelectorAll("td[class=title] a"); | |
var r = []; | |
for (var i=0; i<l.length; i++) { | |
r[r.length] = [l[i].text, l[i].href]; | |
} | |
return r; | |
}); | |
this.each(links, function(self, link_data) { | |
self.thenOpen(link_data[1], function() { | |
this.capture(link_data[0] + '.pdf') | |
}); | |
}); | |
}); | |
casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment