in ,

404 Checker

After getting a ping from a friend of mine, I updated my web scrapper and modified it a bit to fit his needs.  He wanted to catch 404’s… so I sent him my old web scrapper.  The problem was though, his test machine had limited memory.  Due to that it was crashing out and not completing the test.  My old code would leverage Anemone to crawl, and then put each URL into an array.  Then iterate over the array via some browser automation framework (i.e. Watir.)

The reason for the browser iteration, is that you can leverage something like Watir to validate specific elements on each page.  In my case I had errors Anemone wasn’t catching. So Watir was a great help.  But because of his machine crashing on run, I modified the code a bit:


require 'anemone'
require 'watir-webdriver'
@browser = :firefox
base_url = "http://yoursite"
puts 'Crawling site'
Anemone.crawl(base_url) do |a|
  URLS = []
  a.on_every_page do |p|
    if p.html?
      URLS << p.url.to_s
      URLS.each do |u|
        if @browser.text.include? "404"
            p u + " FAILED: page is broken"
          p "This page is good: " + u

That’s what fixed it.  So what we’re doing here, is while Anemone is finding a link it’s crawl, it pulls it up in a browser.  I put in a simple browser check. But more could be added.  Failures get output to the screen (but could be saved to a csv file.)  Passes are put to the screen to get an idea of the full breadth of testing.

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Written by Admin

I work for a Telecom company writing and testing software. My passion for writing code is expressed through this blog. It's my hope that it gives hope to any and all who are self-taught.


Leave a Reply


Python Port Scanner Revisited

Python Classes