public
Last active

A link checker using CasperJS

  • Download Gist
waiter.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*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/'; // URL to check
 
casper.checkLink = function checkLink() {
this.echo('Setting up check steps...');
this.open(url).then(function() {
if (this.exists('#selector-to-your-link')) {
this.echo('link was found, clicking');
this.thenClick('#selector-to-your-link').then(function() {
// add stuff to be done
// ... then exit
this.echo('Done.').exit();
});
} else {
this.warn('Link not found, scheduling another attempt');
this.wait(interval);
}
});
this.run(this.checkLink);
};
 
casper.start().checkLink();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.