该代码需要一些不良的html,使用Tidy库进行清理,然后将其传递给HtmlLib.Reader()。Python - 整理HTML解析
import tidy
options = dict(output_xhtml=1,
add_xml_decl=1,
indent=1,
tidy_mark=0)
from xml.dom.ext.reader import HtmlLib
reader = HtmlLib.Reader()
doc = reader.fromString(tidy.parseString("<Html>Bad Html.", **options))
我不是通过用正确的类型,似乎fromString,这种回溯:
Traceback (most recent call last):
File "getComicEmbed.py", line 33, in <module>
doc = reader.fromString(tidy.parseString("<Html>Bad Html.</b>", **options))
File "C:\Python26\lib\site-packages\_xmlplus\dom\ext\reader\HtmlLib.py", line 67, in fromString
stream = reader.StrStream(str)
File "C:\Python26\lib\site-packages\_xmlplus\dom\ext\reader\__init__.py", line 24, in StrStream
return cStringIO.StringIO(st)
TypeError: expected read buffer, _Document found
我应该怎么做不同?谢谢!
tidy'模块在导入哪个'? PyPI显示至少两个,我不确定是否包含在'tidy'源代码分发包中的那个(对于ubuntu的'tidy'包)是其中之一。 – intuited 2010-10-15 09:55:55