htmlmin: pass in string get error: unicode argument expected, got 'str'

htmlmin: pass in string get error: unicode argument expected, got 'str'

我是 Python 的新手,无法理解这一点。我有一个存储为 myHtmlString 的 html 字符串,但出现错误:需要 unicode 参数,得到 'str'。我正在尝试缩小 html 字符串并删除多余的空格。

import htmlmin

myHtmlString ="""<body   style="background-color: tomato;">
                <h1>  htmlmin   rocks</h1>
                 <pre>
                    and rolls
                 </pre>
                 </body>"""

myHtmlString2  = htmlmin.minify(myHtmlString, remove_empty_space=True)

知道了:

myHtmlString2  = htmlmin.minify(unicode(myHtmlString, "utf-8"), remove_empty_space=True)