rendered paste body#!/usr/bin/python
import urllib, urllib2
from urlparse import urlparse
from sgmllib import SGMLParser
class FetchLinks(SGMLParser):
def reset(self):
SGMLParser.reset(self)
self.urls = []
def start_a(self, attrs):
href = [v for k, v in attrs if k=='href']
if href:
self.urls.extend(href)
openURL = urllib.urlopen('http://guide.real.com')
fetchURLs = FetchLinks()
fetchURLs.feed(openURL.read())
openURL.close()
fetchURLs.close()
for URL in fetchURLs.urls:
try:
urllib2.urlopen(URL)
print URL
except urllib2.HTTPError, e:
if e.coda[0] == 2:
print 'Success'
if e.code == 401:
print 'Not Authorized'
if e.code == 404:
print 'Not Found'
if e.code == 503:
print 'Service Unavailable'
else:
print 'Not known'