Domanda

This is my code:

from html5lib import treebuilders, HTMLParser
parser = HTMLParser(tree=treebuilders.getTreeBuilder("lxml"))
parser.parse("hello world!")
print parser.errors

what cause the error?

But the doc of html5lib use this:

import html5lib
parser = html5lib.HTMLParser(tree=html5lib.getTreeBuilder("dom"))
minidom_document = parser.parse("<p>Hello World!")
È stato utile?

Soluzione 2

when I use the after code it success:

parser.parse("<!DOCTYPE html>hello world!")

Altri suggerimenti

HTMLParser.errors contains all parse errors from parsing the document; html5lib should handle all parse errors gracefully by default (and yes, the documentation does contain examples that generate parse errors — the aim is to document the API, not show good HTML usage!), and hence unless you are for some reason concerned about parse errors (unless you have a good reason to be, don't be), its value is totally irrelevant.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top