working on it ...

Filters

Explore Public Snippets

Sort by

Found 1 snippet

    public by Gabrielyan  2061  0  6  1

    Quick link checker with CasperJS

    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()

    List Complete ( 1 snippet total )

    Cannot find what you were looking for?
    Ask the Snip2Code Community

    • Public Snippets
    • Channels Snippets