Created on 2003-05-12 11:37 by smroid, last changed 2009-04-05 18:45 by georg.brandl. This issue is now closed.
I'm using 2.3a2.
HTMLParser correctly raises a "malformed start tag"
error on:
<meta NAME=DESCRIPTION Content=Lands' End quality...
outerwear and more.>
because my application is imprecise by nature (web
scraping), I want to be able to continue after such errors.
I can override the error() method to not raise an
exception. To make this work, I also needed to alter
HTMLParser.py, near line 316, to read as:
self.updatepos(i, j)
self.error("malformed start tag")
return j # ADDED THIS LINE
raise AssertionError("we should not get here!")
My enhancement request is for every place where
self.error() is called, to ensure that the "override
error() to not raise an exception" continuation
strategy works as well as can be hoped.
Thanks,
Steve
Logged In: YES
user_id=555155
Fixed by my patch against 2.3.3.
The patch adds recovery to ensure progress and tries to not
miss any data in the input.
The error() method is now commented as being overridable,
just def error(): pass to ignore any parsing errors.
Logged In: YES
user_id=555155
This problem is actually more widespread than previously
indicated. Not only do all calls to self.error where that
function returns need to cope with that, and recover (the
HTMLParser defines that every character in the input will be
visited exactly once), but other modules are also affected.
In particular, feeding HTML (from spam) with a tag <!12345>
into HTMLParser causes markupbase._scan_name to emit an
error that now needs to recover.
The patch in #917188 may be better than the one suggested
here as it deals with all places where self.error() can return.
More is needed to fix the problem completely.
In markupbase.py, at least this is necessary
--- markupbase.py.orig Sat Apr 03 17:43:48 2004
+++ markupbase.py Sat Apr 03 18:02:48 2004
@@ -377,6 +377,8 @@
else:
self.updatepos(declstartpos, i)
self.error("expected name token")
+ return None,rawdata.find(">",i)
# To be overridden -- handlers for unknown objects
def unknown_decl(self, data):
Superseder: issue 755660.
Setting as superseder.