Created
October 2, 2014 07:26
-
-
Save penk/ce7357728a0274ae0e68 to your computer and use it in GitHub Desktop.
8comic downloader written in casperjs
This file contains hidden or 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: casperjs 8comic.js http://new.comicvip.com/show/cool-1050.html | |
var casper = require('casper').create({ | |
pageSettings: { | |
webSecurityEnabled: false | |
} | |
}); | |
var pages, currentPage; | |
casper.start(casper.cli.args[0], function(){ | |
pages = this.evaluate(function(){ | |
return document.querySelector("#pageindex").length | |
}); | |
}); | |
casper.on('load.finished', function (status) { | |
if (status === 'success') { | |
var img = this.evaluate(function(){ return document.querySelector("#TheImg").src }); | |
this.echo(img, 'INFO'); | |
this.download(img, img.split('/').reverse()[0]); | |
currentPage = this.evaluate(function(){ return document.querySelector("#pageindex").selectedIndex }); | |
if (currentPage === pages -1 ) { | |
casper.exit(); | |
} | |
this.then(function(){ this.click('#next') }) | |
} | |
}); | |
casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment