Skip to content

Instantly share code, notes, and snippets.

@zloyrusskiy
Created September 2, 2016 21:52
Show Gist options
  • Save zloyrusskiy/c5c01985812b4c935eb543b5faa2949f to your computer and use it in GitHub Desktop.
Save zloyrusskiy/c5c01985812b4c935eb543b5faa2949f to your computer and use it in GitHub Desktop.
var OUTPUT_DIR = 'pics';
var fs = require('fs');
if (!fs.exists(OUTPUT_DIR)) {
fs.makeDirectory(OUTPUT_DIR);
}
var casper = require('casper').create({
verbose: true,
logLevel: "debug"
});
casper.start('http://smoochnyc.com/');
casper.viewport(1024,4000);
// casper.then(function () {
// scrollDown(0);
// });
// function scrollDown(lastScrollTop) {
// var newScrollTop;
// casper.then(function () {
// newScrollTop = casper.evaluate(function() {
// var body = document.querySelector('body');
// var delta = body.offsetHeight;
// __utils__.echo('scrolling');
// body.scrollTop += delta;
// return body.scrollTop;
// });
// });
// casper.wait(5000);
// casper.then(function () {
// if (newScrollTop !== lastScrollTop) {
// scrollDown(newScrollTop);
// }
// });
// }
casper.then(function () {
var links = casper.evaluate(function () {
var images = document.querySelectorAll('#main img');
return Array.prototype.slice.call(images)
.map(function (el) {
return el.dataset.original;
});
});
casper.echo(links);
links.forEach(function (link, index) {
var pic_name = link.replace(/^.+\//, '');
var full_link = casper.getCurrentUrl() + link.replace(/^\//, '');
casper.echo('downloading: ' + full_link + ' to: ' + pic_name);
casper.then(function () {
casper.download(link, OUTPUT_DIR + '/' + pic_name);
}).wait(1000);
});
});
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment