Skip to content

Instantly share code, notes, and snippets.

@n1k0
Last active August 5, 2016 04:58
Show Gist options
  • Save n1k0/4391477 to your computer and use it in GitHub Desktop.
Save n1k0/4391477 to your computer and use it in GitHub Desktop.
A link checker using CasperJS
/*jshint strict:false*/
/*global CasperError console phantom require*/
var casper = require('casper').create({
logLevel: "debug",
verbose: true
}),
interval = 1000 * 60, // 1 minute
url = 'http://google.com/';
var checkLink = function checkLink() {
this.echo('Setting up check...');
this.thenOpen(url, function() {
this.echo(this.getCurrentUrl());
var found = this.exists('#selector-to-your-link');
this.echo(found ? 'link was found' : 'link not found');
if (found) {
this.thenClick('#selector-to-your-link').then(function() {
// add stuff to be done
// ... then exit
this.echo('Done.').exit();
});
} else {
this.echo('Scheduling another attempt');
this.wait(interval);
}
});
this.echo('Check steps added');
this.run(checkLink);
};
casper.start().then(function() {
this.echo('Daemon started');
}).run(checkLink);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment