简体   繁体   中英

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

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.

当我使用after代码成功时:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM