def error(self, message): if self.error_count > 10 or self.started: raise compat_html_parser.HTMLParseError(message, self.getpos()) self.rawdata = '\n'.join( self.html.split('\n')[self.getpos()[0]:]) # skip one line self.error_count += 1 self.goahead(1)
def handle_endtag(self, tag): """To handle the end of a tag. If a script tag is opened, ignore all the junk in there until the tag is closed. """ if self.stack: if self.stack[-1].tag == "script" and tag != "script": # ignore everything inside script tag return if tag != self.stack[-1].tag: # tag mismatch if any(n.tag == tag for n in self.stack): msg = "no closing tag for '<{0}>'".format( self.stack[-1].tag) pos = self.stack[-1].start else: msg = "no opening tag for '</{0}>'".format(tag) pos = self.getpos() raise HTMLParser.HTMLParseError(msg, pos) self.stack[-1].end = self.getpos() self.stack.pop(-1)