Посмотрите, что происходит.
>>> from HTMLParser import HTMLParser
>>> import urllib2
>>> class City2Parser(HTMLParser):
... def handle_starttag(self,tag,attrs):
... if tag == 'h2':
... print 'h2'
...
>>> req = urllib2.Request('http://www.worldgolf.com/courses/usa/massachusetts/')
>>> html = urllib2.urlopen(req)
>>> parser = City2Parser()
>>> parser.feed(html.read())
h2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/HTMLParser.py", line 109, in feed
self.goahead(0)
File "/usr/lib/python2.7/HTMLParser.py", line 151, in goahead
k = self.parse_starttag(i)
File "/usr/lib/python2.7/HTMLParser.py", line 232, in parse_starttag
endpos = self.check_for_whole_start_tag(i)
File "/usr/lib/python2.7/HTMLParser.py", line 307, in check_for_whole_start_tag
self.error("malformed start tag")
File "/usr/lib/python2.7/HTMLParser.py", line 116, in error
raise HTMLParseError(message, self.getpos())
HTMLParser.HTMLParseError: malformed start tag, at line 249, column 30
Он жалуется на неверный HTML <br style="clear:left;"
.HTMLParser заботится о получении действительного HTML.