2019-04-08 23:22:26 +08:00

2 lines
3.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="body" role="main"><div class="section" id="module-html"><h1><span class="yiyi-st" id="yiyi-10">20.1. <a class="reference internal" href="#module-html" title="html: Helpers for manipulating HTML."><code class="xref py py-mod docutils literal"><span class="pre">html</span></code></a> - 超文本标记语言的支持</span></h1><p><span class="yiyi-st" id="yiyi-11"><strong>源代码:</strong><a class="reference external" href="https://hg.python.org/cpython/file/3.5/Lib/html/__init__.py">Lib/html/__init__.py</a></span></p><p><span class="yiyi-st" id="yiyi-12">此模块定义操作HTML的实用程序。</span></p><dl class="function"><dt id="html.escape"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">html.</code><code class="descname">escape</code><span class="sig-paren">(</span><em>s</em>, <em>quote=True</em><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-14">转换字符串<em>s</em>中的<code class="docutils literal"><span class="pre">&amp;</span></code><code class="docutils literal"><span class="pre">&lt;</span></code><code class="docutils literal"><span class="pre">&gt;</span></code>字符为HTML安全的序列。</span><span class="yiyi-st" id="yiyi-15">如果你需要在HTML中显示可能包含此类字符的文本请使用此选项。</span><span class="yiyi-st" id="yiyi-16">如果可选标志<em>quote</em>为真,则还会转换字符(<code class="docutils literal"><span class="pre">"</span></code>)和(<code class="docutils literal"><span class="pre">'</span></code>这对引号分隔的HTML属性值中的内容有帮助<code class="docutils literal"><span class="pre">&lt;a</span> <span class="pre">href="..."&gt;</span></code></span></p><div class="versionadded"><p><span class="yiyi-st" id="yiyi-17"><span class="versionmodified">版本3.2中的新功能。</span></span></p></div></dd></dl><dl class="function"><dt id="html.unescape"><span class="yiyi-st" id="yiyi-18"> <code class="descclassname">html.</code><code class="descname">unescape</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-19">转换字符串<em>s</em>中所有命名和数字字符引用(例如<code class="docutils literal"><span class="pre">&amp;gt;</span></code><code class="docutils literal"><span class="pre">&amp;#62;</span></code><code class="docutils literal"><span class="pre">&amp;x3e;</span></code>为对应的Unicode字符。</span>
<span class="yiyi-st" id="yiyi-21">对于有效的和无效的字符引用此函数使用HTML 5标准定义的规则以及<a class="reference internal" href="html.entities.html#html.entities.html5" title="html.entities.html5"><code class="xref py py-data docutils literal"><span class="pre">list</span> <span class="pre">of</span> <span class="pre">HTML</span> <span class="pre">5</span> <span class="pre">named</span> <span class="pre">character</span> <span class="pre">references</span></code></a></span></p><div class="versionadded"><p><span class="yiyi-st" id="yiyi-22"><span class="versionmodified">版本3.4中的新功能。</span></span></p></div></dd></dl><p><span class="yiyi-st" id="yiyi-23"><code class="docutils literal"><span class="pre">html</span></code>包中的子模块包括:</span></p><ul class="simple"><li><span class="yiyi-st" id="yiyi-24"><a class="reference internal" href="html.parser.html#module-html.parser" title="html.parser: A simple parser that can handle HTML and XHTML."><code class="xref py py-mod docutils literal"><span class="pre">html.parser</span></code></a> - 具有宽松解析模式的HTML/XHTML解析器</span></li><li><span class="yiyi-st" id="yiyi-25"><a class="reference internal" href="html.entities.html#module-html.entities" title="html.entities: Definitions of HTML general entities."><code class="xref py py-mod docutils literal"><span class="pre">html.entities</span></code></a> - HTML实体的定义</span></li></ul></div></div>