1

TypeError: insertDoctype() takes exactly 4 arguments (2 given)一起使用 lxml 和 html5lib 时出现错误。似乎(链接insertDoctype)中的方法需要 4 个参数,而 html5lib 代码(链接)使用 2 个参数调用它。我是否以某种方式使用了这个错误?lxml.html._html5builder.TreeBuilder

这些是我正在使用的版本:

$ pip freeze
BeautifulSoup==3.2.0
distribute==0.6.14
html5lib==0.90
lxml==2.3
mechanize==0.2.4
wsgiref==0.1.2

我的源代码:

from lxml.html import html5parser

html5parser.document_fromstring('''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head><title>t</title><body></body></html>''')

和错误:

Traceback (most recent call last):
  File "/tmp/t.py", line 4, in <module>
    <html><head><title>t</title><body></body></html>''')
  File "/Users/me/.virtualenvs/myenv/lib/python2.6/site-packages/lxml/html/html5parser.py", line 54, in document_fromstring
    return parser.parse(html, useChardet=guess_charset).getroot()
  File "/Users/me/.virtualenvs/myenv/lib/python2.6/site-packages/html5lib/html5parser.py", line 211, in parse
    parseMeta=parseMeta, useChardet=useChardet)
  File "/Users/me/.virtualenvs/myenv/lib/python2.6/site-packages/html5lib/html5parser.py", line 111, in _parse
    self.mainLoop()
  File "/Users/me/.virtualenvs/myenv/lib/python2.6/site-packages/html5lib/html5parser.py", line 189, in mainLoop
    self.phase.processDoctype(token)
  File "/Users/me/.virtualenvs/myenv/lib/python2.6/site-packages/html5lib/html5parser.py", line 482, in processDoctype
    self.tree.insertDoctype(token)
TypeError: insertDoctype() takes exactly 4 arguments (2 given)
4

0 回答 0