Created
April 1, 2015 03:12
-
-
Save syon/1404f3d416371b585969 to your computer and use it in GitHub Desktop.
CasperJS sample
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 props = { | |
// Chrome | |
pc:{ | |
ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36", | |
//viewport: { width: 2560, height: 1440 } | |
viewport: { width: 640, height: 480 } | |
}, | |
// iPhone 5, iOS 8.0.2 | |
mobile: { | |
ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A405 Safari/600.1.4", | |
viewport: { width: 640, height: 1136 } | |
} | |
}; | |
var casper = require('casper').create(); | |
//var url = casper.cli.args[0]; | |
var prop = casper.cli.args[1] == "mobile" ? props.mobile : props.pc; | |
casper.start(); | |
casper.userAgent(prop.ua); | |
casper.zoom(1); | |
casper.viewport(prop.viewport.width, prop.viewport.height); | |
var urls = [ | |
"http://www.yahoo.co.jp" | |
, "http://google.com" | |
, "http://ja.wikipedia.org/" | |
, "https://github.com/" | |
]; | |
urls.map(function(url,idx){ | |
casper.then(function(){ | |
casper.open( url ).then(function(){ | |
console.log( "capturing[" + idx + "]: " + url ); | |
this.capture( idx + '.png' ); | |
}); | |
}); | |
}); | |
casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment