57 8

Quick link checker with CasperJS

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
casper = require("casper").create() errors = [] errorHandler = (url, status, msg)-> errors.push {url: url, status: status, msg: msg}; if casper.cli.has(0) url = casper.cli.get(0) else casper.echo "Missing url argument", "ERROR" casper.exit() #---------------------------------------------------- casper.start url, (res)-> if not res.status or res.status isnt 200 errorHandler(url, res.status, res.statusText or 'Something Wrong') links = @getElementsAttribute('a', 'href') links = links.filter (link)-> # if need... link isnt '#' @each links, (self, link) -> self.thenOpen link, (res) -> if res.status and res.status is 200 @echo "#{link} - #{res.status} #{res.statusText}", 'INFO' else errors.push {url: link, status: res.status, msg: res.statusText} .run -> if errors.length > 0 @echo "Errors: #{errors.length}" for error in errors @echo "url: #{error.url}, status: #{error.status}, msg: #{error.msg}", 'ERROR' else @echo "All Done!", "INFO" @exit()
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus