Last active
August 5, 2016 04:58
-
-
Save n1k0/4391477 to your computer and use it in GitHub Desktop.
A link checker using CasperJS
This file contains hidden or 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
/*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