in reply to How can I do this better?

  1. You accept HTML and GIF, but not JPEG or PNG? Are you really sure that's what you want to do?
  2. You're sleeping one too many times for failing urls.
  3. If you take a look at why you're unable to fetch a url, you may discover that it is pointless to try again two times (costing you another 2 x (roundtrip + 5) seconds, with an extra 5 seconds thrown in if you don't fix (2)).