对于Python 3.5。
有人可以指点我在Python 3中使用 html5tidy 的一些文档吗?我很惊讶多次搜索不会返回任何内容。
在Python 3中, html5tidy.py 中的文档声明:
"""
HTML5Tidy
=========
Simple wrapper around html5lib & lxml.etree to "tidy" html in the wild to
well-formed xml/html
Usage
-----
>>> from html5tidy import tidy
>>> tidy('some text')
'<html><head/><body>some text</body></html>'
Dependencies
------------
* [html5lib](http://code.google.com/p/html5lib/)
* [lxml](http://lxml.de/)
好的,所以我有所有的东西:
>>> import html5lib
>>> dir(html5lib)
['HTMLParser', '__all__', '__builtins__', '__cached__', [and so on]]
>>>
>>> import lxml
>>> dir(lxml)
['__builtins__', '__cached__', '__doc__', '__file__', [and so on]]
但我注意到 dir(tidy)只返回双下划线结果:
>>> from html5tidy import tidy
>>> dir(tidy)
['__annotations__', '__call__', '__class__', [and so on...]'__subclasshook__']
所以我打开一个包含HTML的文件 untidiedHTML 。
>>> print(untidiedHTML)
<!DOCTYPE html>
<html id="ng-app" lang="en" ng-app="TH" style="" xmlns:ng="http://angularjs.org">
<head ng-controller="DZHeadController">
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
<title ng-bind="service.title">
What the Heck Is OAuth? - DZone Security
</title>
<link href="WhatIsOAuth0200_files/tranquility.css" rel="stylesheet" type="text/css"/>
</head>
<body class="tranquility" >
... and so on...
然后根据HTML5整洁文档我尝试:
from html5tidy import tidy
tidiedHTML = tidy(untidiedHTML)
产生:
Traceback (most recent call last):
File "[path to my Python source file].py", line 50, in <module>
tidiedHTML = tidy(untidiedHTML)
File "/usr/local/lib/python3.5/dist-packages/html5tidy.py", line 61, in tidy
parts = [parser.parse(src, encoding=encoding, parseMeta=parseMeta, useChardet=useChardet)]
File "/usr/local/lib/python3.5/dist-packages/html5lib/html5parser.py", line 289, in parse
self._parse(stream, False, None, *args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/html5lib/html5parser.py", line 130, in _parse
self.tokenizer = _tokenizer.HTMLTokenizer(stream, parser=self, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/html5lib/_tokenizer.py", line 36, in __init__
self.stream = HTMLInputStream(stream, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/html5lib/_inputstream.py", line 149, in HTMLInputStream
return HTMLUnicodeInputStream(source, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'parseMeta'
我不知道该怎么做。我已经搜索了解释如何从Python 3调用 html5tidy 的文档,但我已经空了......
答案 0 :(得分:1)
该库已损坏和/或无法与python 3.5一起使用。我安装并遇到了与html5lib.HTMLParser https://github.com/aleray/html5tidy/blob/master/html5tidy.py#L57
相关的错误Theres one贡献者和包裹未在6年内更新
您的选择