Skip to content

Instantly share code, notes, and snippets.

@cheeming
Last active August 29, 2015 14:06
Show Gist options
  • Save cheeming/d2b732052eaa07203fae to your computer and use it in GitHub Desktop.
Save cheeming/d2b732052eaa07203fae to your computer and use it in GitHub Desktop.
Download current HackerNews articles into PDF (CasperJS)
// 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