Skip to content

Instantly share code, notes, and snippets.

@apparition47
Last active April 3, 2017 03:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apparition47/a5384e90dbabba26fb10df3ac7a749f6 to your computer and use it in GitHub Desktop.
Save apparition47/a5384e90dbabba26fb10df3ac7a749f6 to your computer and use it in GitHub Desktop.
NCIX.com Newsletter Rewards Claimer
/**
* CasperJS script to claim NCIX.com newsletter points by batch of emails.
* Takes newsletter email URL as CLI argument.
* All emails filled in below must be registered to NCIX.com.
*
* For demo purposes only.
*/
var emails = [
'ncix_registerd@example.net',
'ncix_registerd2@example.net',
]
var casper = require('casper').create({
pageSettings: {
loadImages: false,
loadPlugins: false
},
// verbose: true,
// logLevel: "debug"
});
if (!emails || !emails.length) {
casper.die('Please edit this file and add emails');
}
// read CLI arguments
if (!casper.cli.args.length) {
casper.die('usage: casperjs index.js "<newsletterrewardsUrl>"');
}
var newsletterrewardsUrl = casper.cli.args[0];
function getCaptcha() {
return casper.evaluate(function() {
var el = document.getElementsByTagName('font');
for (var i=0; i<el.length; i++) {
if (el[i].getAttribute('style') === 'background:yellow') {
return el[i].textContent;
}
}
})
}
casper.start();
// open claim page for each email then fill in captcha
casper.then(function() {
this.each(emails, function(self, email, i) {
this.thenOpen(newsletterrewardsUrl, function() {
casper.waitFor(function check() {
return getCaptcha();
}, function then() {
var captcha = getCaptcha();
this.echo(this.getTitle() + ' ' + email + ' with captcha ' + captcha, 'INFO');
this.fillSelectors('form[name="claimpoints"]', {
'input[name="email"]': email,
'input[name="captcha"]': captcha
}, true);
// this.capture('site'+email.substring(5)+'.png');
}, function onTimeout() {
this.die('Failed - bad url?')
});
// read alert popup for feedback
casper.waitForAlert(function(response) {
this.echo("Alert received: " + response.data, 'COMMENT');
// passed
if (/will add to your account/.test(response.data)) {
}
// not-fatal errors
// skip to next if already claimed for this email
else if (/you have already claimed/.test(response.data)) {
} else if (/have to Register/.test(response.data)) {
} else {
// probably failed captcha so should abort
this.die('Failed');
}
});
});
});
});
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment