Skip to content

Instantly share code, notes, and snippets.

@nerder
Created March 21, 2016 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerder/7176f55d711cf64a892a to your computer and use it in GitHub Desktop.
Save nerder/7176f55d711cf64a892a to your computer and use it in GitHub Desktop.
var casper = require('casper').create({
remoteScripts: [
'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.6.1/lodash.js'
],
pageSettings: {
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.1500.71 Safari/537.36'
},
viewport: {
width: 1280,
height: 1024
},
waitTimeout: 60000,
logLevel: 'debug',
verbose: true
});
casper.start('https://web.whatsapp.com/', function(){
this.echo('Starting...')
this.waitForSelector('.qrcode', function() {
this.captureSelector('whatsapp.png', 'html');
this.echo('Screeshot Taken!')
});
});
casper.run();
var system = require('system');
var page = new WebPage();
page.settings.userAgent ='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.1500.71 Safari/537.36';
page.viewportSize = {width: 1280, height: 1024};
console.log(page.settings.userAgent);
page.open('https://web.whatsapp.com/', function (status) {
if (status !== 'success') {
output.errors.push('Unable to access network');
} else {
window.setTimeout(function () {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js",function() {
page.clipRect = {
top: 214,
left: 296,
width: 250,
height: 250
}
page.render('whatsapp_qrcode.jpeg', {format: 'jpeg', quality: '100'});
console.log('QrCode Saved!');
phantom.exit();
});
}, 10500);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment