htmlHyperText Markup Language support超文本标记语言支持

Source code: Lib/html/__init__.py


This module defines utilities to manipulate HTML.此模块定义用于操作HTML的实用程序。

html.escape(s, quote=True)

Convert the characters &, < and > in string s to HTML-safe sequences. 将字符串s中的字符&<>转换为HTML安全序列。Use this if you need to display text that might contain such characters in HTML. 如果需要在HTML中显示可能包含此类字符的文本,请使用此选项。If the optional flag quote is true, the characters (") and (') are also translated; this helps for inclusion in an HTML attribute value delimited by quotes, as in <a href="...">.如果可选标志quotetrue,则字符(")和(')也会被翻译;这有助于包含在由引号分隔的HTML属性值中,如在<a href="...">中。

New in version 3.2.版本3.2中新增。

html.unescape(s)

Convert all named and numeric character references (e.g. &gt;, &#62;, &#x3e;) in the string s to the corresponding Unicode characters. 转换所有命名和数字字符引用(例如&gt;&#62;&#x3e;)将字符串中的s转换为相应的Unicode字符。This function uses the rules defined by the HTML 5 standard for both valid and invalid character references, and the list of HTML 5 named character references.此函数使用HTML 5标准为有效和无效字符引用定义的规则,以及HTML 5命名字符引用列表

New in version 3.4.版本3.4中新增。


Submodules in the html package are:html包中的子模块包括:

  • html.parserHTML/XHTML parser with lenient parsing mode具有宽松解析模式的HTML/XHTML解析器

  • html.entitiesHTML entity definitionsHTML实体定义