#!/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'] openURL = urllib.urlopen('http://guide.real.com') fetchURLs = FetchLinks() fetchURLs.feed(openURL.read()) openURL.close() fetchURLs.close() #URL = 'http://guide.real.com' for URL in fetchURLs.urls: try: urllib2.urlopen(URL) print 'Opening link ' % URL except urllib2.HTTPError, e: if e.code == 401: print 'Not Authorized' if e.code == 404: print 'Not Found' if e.code == 503: print 'Service Unavailable' else: print 'Success'