Refactor and hopefully fix http error catching - untested

I have hopefully fixed the URL error and I also re-factored the code a bit.

The problem:
    except urllib2.URLError as e:
was being used instead of
    except urllib2.HTTPError as e:

I wasn't able to test it as I don't have a netsoc account but there hopefully will only be the odd syntax error.