gnemoug
gnemoug

Reputation: 467

get ''expected-doctype-but-got-chars " error when i use html5lib of python?

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!")

Upvotes: 0

Views: 87

Answers (2)

gsnedders
gsnedders

Reputation: 5692

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.

Upvotes: 1

gnemoug
gnemoug

Reputation: 467

when I use the after code it success:

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

Upvotes: 0

Related Questions