gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

658 lines
50KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="html.parser — Simple HTML and XHTML parser" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/html.parser.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/html/parser.py This module defines a class HTMLParser which serves as the basis for parsing text files formatted in HTML (HyperText Mark-up Language) and XHTML. Example HTML Parser..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/html/parser.py This module defines a class HTMLParser which serves as the basis for parsing text files formatted in HTML (HyperText Mark-up Language) and XHTML. Example HTML Parser..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>html.parser — Simple HTML and XHTML parser &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="html.entities — Definitions of HTML general entities" href="html.entities.html" />
  33. <link rel="prev" title="html — HyperText Markup Language support" href="html.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/html.parser.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">html.parser</span></code> — Simple HTML and XHTML parser</a><ul>
  86. <li><a class="reference internal" href="#example-html-parser-application">Example HTML Parser Application</a></li>
  87. <li><a class="reference internal" href="#htmlparser-methods"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code> Methods</a></li>
  88. <li><a class="reference internal" href="#examples">Examples</a></li>
  89. </ul>
  90. </li>
  91. </ul>
  92. </div>
  93. <div>
  94. <h4>Previous topic</h4>
  95. <p class="topless"><a href="html.html"
  96. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">html</span></code> — HyperText Markup Language support</a></p>
  97. </div>
  98. <div>
  99. <h4>Next topic</h4>
  100. <p class="topless"><a href="html.entities.html"
  101. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">html.entities</span></code> — Definitions of HTML general entities</a></p>
  102. </div>
  103. <div role="note" aria-label="source link">
  104. <h3>This Page</h3>
  105. <ul class="this-page-menu">
  106. <li><a href="../bugs.html">Report a Bug</a></li>
  107. <li>
  108. <a href="https://github.com/python/cpython/blob/main/Doc/library/html.parser.rst"
  109. rel="nofollow">Show Source
  110. </a>
  111. </li>
  112. </ul>
  113. </div>
  114. </nav>
  115. </div>
  116. </div>
  117. <div class="related" role="navigation" aria-label="related navigation">
  118. <h3>Navigation</h3>
  119. <ul>
  120. <li class="right" style="margin-right: 10px">
  121. <a href="../genindex.html" title="General Index"
  122. accesskey="I">index</a></li>
  123. <li class="right" >
  124. <a href="../py-modindex.html" title="Python Module Index"
  125. >modules</a> |</li>
  126. <li class="right" >
  127. <a href="html.entities.html" title="html.entities — Definitions of HTML general entities"
  128. accesskey="N">next</a> |</li>
  129. <li class="right" >
  130. <a href="html.html" title="html — HyperText Markup Language support"
  131. accesskey="P">previous</a> |</li>
  132. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  133. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  134. <li class="switchers">
  135. <div class="language_switcher_placeholder"></div>
  136. <div class="version_switcher_placeholder"></div>
  137. </li>
  138. <li>
  139. </li>
  140. <li id="cpython-language-and-version">
  141. <a href="../index.html">3.12.3 Documentation</a> &#187;
  142. </li>
  143. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  144. <li class="nav-item nav-item-2"><a href="markup.html" accesskey="U">Structured Markup Processing Tools</a> &#187;</li>
  145. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">html.parser</span></code> — Simple HTML and XHTML parser</a></li>
  146. <li class="right">
  147. <div class="inline-search" role="search">
  148. <form class="inline-search" action="../search.html" method="get">
  149. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  150. <input type="submit" value="Go" />
  151. </form>
  152. </div>
  153. |
  154. </li>
  155. <li class="right">
  156. <label class="theme-selector-label">
  157. Theme
  158. <select class="theme-selector" oninput="activateTheme(this.value)">
  159. <option value="auto" selected>Auto</option>
  160. <option value="light">Light</option>
  161. <option value="dark">Dark</option>
  162. </select>
  163. </label> |</li>
  164. </ul>
  165. </div>
  166. <div class="document">
  167. <div class="documentwrapper">
  168. <div class="bodywrapper">
  169. <div class="body" role="main">
  170. <section id="module-html.parser">
  171. <span id="html-parser-simple-html-and-xhtml-parser"></span><h1><a class="reference internal" href="#module-html.parser" title="html.parser: A simple parser that can handle HTML and XHTML."><code class="xref py py-mod docutils literal notranslate"><span class="pre">html.parser</span></code></a> — Simple HTML and XHTML parser<a class="headerlink" href="#module-html.parser" title="Link to this heading">¶</a></h1>
  172. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/html/parser.py">Lib/html/parser.py</a></p>
  173. <hr class="docutils" id="index-0" />
  174. <p>This module defines a class <a class="reference internal" href="#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> which serves as the basis for
  175. parsing text files formatted in HTML (HyperText Mark-up Language) and XHTML.</p>
  176. <dl class="py class">
  177. <dt class="sig sig-object py" id="html.parser.HTMLParser">
  178. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">html.parser.</span></span><span class="sig-name descname"><span class="pre">HTMLParser</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">convert_charrefs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser" title="Link to this definition">¶</a></dt>
  179. <dd><p>Create a parser instance able to parse invalid markup.</p>
  180. <p>If <em>convert_charrefs</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code> (the default), all character
  181. references (except the ones in <code class="docutils literal notranslate"><span class="pre">script</span></code>/<code class="docutils literal notranslate"><span class="pre">style</span></code> elements) are
  182. automatically converted to the corresponding Unicode characters.</p>
  183. <p>An <a class="reference internal" href="#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> instance is fed HTML data and calls handler methods
  184. when start tags, end tags, text, comments, and other markup elements are
  185. encountered. The user should subclass <a class="reference internal" href="#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> and override its
  186. methods to implement the desired behavior.</p>
  187. <p>This parser does not check that end tags match start tags or call the end-tag
  188. handler for elements which are closed implicitly by closing an outer element.</p>
  189. <div class="versionchanged">
  190. <p><span class="versionmodified changed">Changed in version 3.4: </span><em>convert_charrefs</em> keyword argument added.</p>
  191. </div>
  192. <div class="versionchanged">
  193. <p><span class="versionmodified changed">Changed in version 3.5: </span>The default value for argument <em>convert_charrefs</em> is now <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
  194. </div>
  195. </dd></dl>
  196. <section id="example-html-parser-application">
  197. <h2>Example HTML Parser Application<a class="headerlink" href="#example-html-parser-application" title="Link to this heading">¶</a></h2>
  198. <p>As a basic example, below is a simple HTML parser that uses the
  199. <a class="reference internal" href="#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> class to print out start tags, end tags, and data
  200. as they are encountered:</p>
  201. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">html.parser</span> <span class="kn">import</span> <span class="n">HTMLParser</span>
  202. <span class="k">class</span> <span class="nc">MyHTMLParser</span><span class="p">(</span><span class="n">HTMLParser</span><span class="p">):</span>
  203. <span class="k">def</span> <span class="nf">handle_starttag</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span> <span class="n">attrs</span><span class="p">):</span>
  204. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Encountered a start tag:&quot;</span><span class="p">,</span> <span class="n">tag</span><span class="p">)</span>
  205. <span class="k">def</span> <span class="nf">handle_endtag</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tag</span><span class="p">):</span>
  206. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Encountered an end tag :&quot;</span><span class="p">,</span> <span class="n">tag</span><span class="p">)</span>
  207. <span class="k">def</span> <span class="nf">handle_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
  208. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Encountered some data :&quot;</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
  209. <span class="n">parser</span> <span class="o">=</span> <span class="n">MyHTMLParser</span><span class="p">()</span>
  210. <span class="n">parser</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="s1">&#39;&lt;html&gt;&lt;head&gt;&lt;title&gt;Test&lt;/title&gt;&lt;/head&gt;&#39;</span>
  211. <span class="s1">&#39;&lt;body&gt;&lt;h1&gt;Parse me!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;&#39;</span><span class="p">)</span>
  212. </pre></div>
  213. </div>
  214. <p>The output will then be:</p>
  215. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Encountered a start tag: html
  216. Encountered a start tag: head
  217. Encountered a start tag: title
  218. Encountered some data : Test
  219. Encountered an end tag : title
  220. Encountered an end tag : head
  221. Encountered a start tag: body
  222. Encountered a start tag: h1
  223. Encountered some data : Parse me!
  224. Encountered an end tag : h1
  225. Encountered an end tag : body
  226. Encountered an end tag : html
  227. </pre></div>
  228. </div>
  229. </section>
  230. <section id="htmlparser-methods">
  231. <h2><a class="reference internal" href="#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> Methods<a class="headerlink" href="#htmlparser-methods" title="Link to this heading">¶</a></h2>
  232. <p><a class="reference internal" href="#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> instances have the following methods:</p>
  233. <dl class="py method">
  234. <dt class="sig sig-object py" id="html.parser.HTMLParser.feed">
  235. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">feed</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.feed" title="Link to this definition">¶</a></dt>
  236. <dd><p>Feed some text to the parser. It is processed insofar as it consists of
  237. complete elements; incomplete data is buffered until more data is fed or
  238. <a class="reference internal" href="#html.parser.HTMLParser.close" title="html.parser.HTMLParser.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> is called. <em>data</em> must be <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>.</p>
  239. </dd></dl>
  240. <dl class="py method">
  241. <dt class="sig sig-object py" id="html.parser.HTMLParser.close">
  242. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.close" title="Link to this definition">¶</a></dt>
  243. <dd><p>Force processing of all buffered data as if it were followed by an end-of-file
  244. mark. This method may be redefined by a derived class to define additional
  245. processing at the end of the input, but the redefined version should always call
  246. the <a class="reference internal" href="#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> base class method <a class="reference internal" href="#html.parser.HTMLParser.close" title="html.parser.HTMLParser.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a>.</p>
  247. </dd></dl>
  248. <dl class="py method">
  249. <dt class="sig sig-object py" id="html.parser.HTMLParser.reset">
  250. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">reset</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.reset" title="Link to this definition">¶</a></dt>
  251. <dd><p>Reset the instance. Loses all unprocessed data. This is called implicitly at
  252. instantiation time.</p>
  253. </dd></dl>
  254. <dl class="py method">
  255. <dt class="sig sig-object py" id="html.parser.HTMLParser.getpos">
  256. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">getpos</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.getpos" title="Link to this definition">¶</a></dt>
  257. <dd><p>Return current line number and offset.</p>
  258. </dd></dl>
  259. <dl class="py method">
  260. <dt class="sig sig-object py" id="html.parser.HTMLParser.get_starttag_text">
  261. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">get_starttag_text</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.get_starttag_text" title="Link to this definition">¶</a></dt>
  262. <dd><p>Return the text of the most recently opened start tag. This should not normally
  263. be needed for structured processing, but may be useful in dealing with HTML “as
  264. deployed” or for re-generating input with minimal changes (whitespace between
  265. attributes can be preserved, etc.).</p>
  266. </dd></dl>
  267. <p>The following methods are called when data or markup elements are encountered
  268. and they are meant to be overridden in a subclass. The base class
  269. implementations do nothing (except for <a class="reference internal" href="#html.parser.HTMLParser.handle_startendtag" title="html.parser.HTMLParser.handle_startendtag"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_startendtag()</span></code></a>):</p>
  270. <dl class="py method">
  271. <dt class="sig sig-object py" id="html.parser.HTMLParser.handle_starttag">
  272. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">handle_starttag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tag</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">attrs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.handle_starttag" title="Link to this definition">¶</a></dt>
  273. <dd><p>This method is called to handle the start tag of an element (e.g. <code class="docutils literal notranslate"><span class="pre">&lt;div</span> <span class="pre">id=&quot;main&quot;&gt;</span></code>).</p>
  274. <p>The <em>tag</em> argument is the name of the tag converted to lower case. The <em>attrs</em>
  275. argument is a list of <code class="docutils literal notranslate"><span class="pre">(name,</span> <span class="pre">value)</span></code> pairs containing the attributes found
  276. inside the tag’s <code class="docutils literal notranslate"><span class="pre">&lt;&gt;</span></code> brackets. The <em>name</em> will be translated to lower case,
  277. and quotes in the <em>value</em> have been removed, and character and entity references
  278. have been replaced.</p>
  279. <p>For instance, for the tag <code class="docutils literal notranslate"><span class="pre">&lt;A</span> <span class="pre">HREF=&quot;https://www.cwi.nl/&quot;&gt;</span></code>, this method
  280. would be called as <code class="docutils literal notranslate"><span class="pre">handle_starttag('a',</span> <span class="pre">[('href',</span> <span class="pre">'https://www.cwi.nl/')])</span></code>.</p>
  281. <p>All entity references from <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 notranslate"><span class="pre">html.entities</span></code></a> are replaced in the attribute
  282. values.</p>
  283. </dd></dl>
  284. <dl class="py method">
  285. <dt class="sig sig-object py" id="html.parser.HTMLParser.handle_endtag">
  286. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">handle_endtag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tag</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.handle_endtag" title="Link to this definition">¶</a></dt>
  287. <dd><p>This method is called to handle the end tag of an element (e.g. <code class="docutils literal notranslate"><span class="pre">&lt;/div&gt;</span></code>).</p>
  288. <p>The <em>tag</em> argument is the name of the tag converted to lower case.</p>
  289. </dd></dl>
  290. <dl class="py method">
  291. <dt class="sig sig-object py" id="html.parser.HTMLParser.handle_startendtag">
  292. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">handle_startendtag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tag</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">attrs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.handle_startendtag" title="Link to this definition">¶</a></dt>
  293. <dd><p>Similar to <a class="reference internal" href="#html.parser.HTMLParser.handle_starttag" title="html.parser.HTMLParser.handle_starttag"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_starttag()</span></code></a>, but called when the parser encounters an
  294. XHTML-style empty tag (<code class="docutils literal notranslate"><span class="pre">&lt;img</span> <span class="pre">...</span> <span class="pre">/&gt;</span></code>). This method may be overridden by
  295. subclasses which require this particular lexical information; the default
  296. implementation simply calls <a class="reference internal" href="#html.parser.HTMLParser.handle_starttag" title="html.parser.HTMLParser.handle_starttag"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_starttag()</span></code></a> and <a class="reference internal" href="#html.parser.HTMLParser.handle_endtag" title="html.parser.HTMLParser.handle_endtag"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_endtag()</span></code></a>.</p>
  297. </dd></dl>
  298. <dl class="py method">
  299. <dt class="sig sig-object py" id="html.parser.HTMLParser.handle_data">
  300. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">handle_data</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.handle_data" title="Link to this definition">¶</a></dt>
  301. <dd><p>This method is called to process arbitrary data (e.g. text nodes and the
  302. content of <code class="docutils literal notranslate"><span class="pre">&lt;script&gt;...&lt;/script&gt;</span></code> and <code class="docutils literal notranslate"><span class="pre">&lt;style&gt;...&lt;/style&gt;</span></code>).</p>
  303. </dd></dl>
  304. <dl class="py method">
  305. <dt class="sig sig-object py" id="html.parser.HTMLParser.handle_entityref">
  306. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">handle_entityref</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.handle_entityref" title="Link to this definition">¶</a></dt>
  307. <dd><p>This method is called to process a named character reference of the form
  308. <code class="docutils literal notranslate"><span class="pre">&amp;name;</span></code> (e.g. <code class="docutils literal notranslate"><span class="pre">&amp;gt;</span></code>), where <em>name</em> is a general entity reference
  309. (e.g. <code class="docutils literal notranslate"><span class="pre">'gt'</span></code>). This method is never called if <em>convert_charrefs</em> is
  310. <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
  311. </dd></dl>
  312. <dl class="py method">
  313. <dt class="sig sig-object py" id="html.parser.HTMLParser.handle_charref">
  314. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">handle_charref</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.handle_charref" title="Link to this definition">¶</a></dt>
  315. <dd><p>This method is called to process decimal and hexadecimal numeric character
  316. references of the form <code class="samp docutils literal notranslate"><span class="pre">&amp;#</span><em><span class="pre">NNN</span></em><span class="pre">;</span></code> and <code class="samp docutils literal notranslate"><span class="pre">&amp;#x</span><em><span class="pre">NNN</span></em><span class="pre">;</span></code>. For example, the decimal
  317. equivalent for <code class="docutils literal notranslate"><span class="pre">&amp;gt;</span></code> is <code class="docutils literal notranslate"><span class="pre">&amp;#62;</span></code>, whereas the hexadecimal is <code class="docutils literal notranslate"><span class="pre">&amp;#x3E;</span></code>;
  318. in this case the method will receive <code class="docutils literal notranslate"><span class="pre">'62'</span></code> or <code class="docutils literal notranslate"><span class="pre">'x3E'</span></code>. This method
  319. is never called if <em>convert_charrefs</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
  320. </dd></dl>
  321. <dl class="py method">
  322. <dt class="sig sig-object py" id="html.parser.HTMLParser.handle_comment">
  323. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">handle_comment</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.handle_comment" title="Link to this definition">¶</a></dt>
  324. <dd><p>This method is called when a comment is encountered (e.g. <code class="docutils literal notranslate"><span class="pre">&lt;!--comment--&gt;</span></code>).</p>
  325. <p>For example, the comment <code class="docutils literal notranslate"><span class="pre">&lt;!--</span> <span class="pre">comment</span> <span class="pre">--&gt;</span></code> will cause this method to be
  326. called with the argument <code class="docutils literal notranslate"><span class="pre">'</span> <span class="pre">comment</span> <span class="pre">'</span></code>.</p>
  327. <p>The content of Internet Explorer conditional comments (condcoms) will also be
  328. sent to this method, so, for <code class="docutils literal notranslate"><span class="pre">&lt;!--[if</span> <span class="pre">IE</span> <span class="pre">9]&gt;IE9-specific</span> <span class="pre">content&lt;![endif]--&gt;</span></code>,
  329. this method will receive <code class="docutils literal notranslate"><span class="pre">'[if</span> <span class="pre">IE</span> <span class="pre">9]&gt;IE9-specific</span> <span class="pre">content&lt;![endif]'</span></code>.</p>
  330. </dd></dl>
  331. <dl class="py method">
  332. <dt class="sig sig-object py" id="html.parser.HTMLParser.handle_decl">
  333. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">handle_decl</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">decl</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.handle_decl" title="Link to this definition">¶</a></dt>
  334. <dd><p>This method is called to handle an HTML doctype declaration (e.g.
  335. <code class="docutils literal notranslate"><span class="pre">&lt;!DOCTYPE</span> <span class="pre">html&gt;</span></code>).</p>
  336. <p>The <em>decl</em> parameter will be the entire contents of the declaration inside
  337. the <code class="docutils literal notranslate"><span class="pre">&lt;!...&gt;</span></code> markup (e.g. <code class="docutils literal notranslate"><span class="pre">'DOCTYPE</span> <span class="pre">html'</span></code>).</p>
  338. </dd></dl>
  339. <dl class="py method">
  340. <dt class="sig sig-object py" id="html.parser.HTMLParser.handle_pi">
  341. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">handle_pi</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.handle_pi" title="Link to this definition">¶</a></dt>
  342. <dd><p>Method called when a processing instruction is encountered. The <em>data</em>
  343. parameter will contain the entire processing instruction. For example, for the
  344. processing instruction <code class="docutils literal notranslate"><span class="pre">&lt;?proc</span> <span class="pre">color='red'&gt;</span></code>, this method would be called as
  345. <code class="docutils literal notranslate"><span class="pre">handle_pi(&quot;proc</span> <span class="pre">color='red'&quot;)</span></code>. It is intended to be overridden by a derived
  346. class; the base class implementation does nothing.</p>
  347. <div class="admonition note">
  348. <p class="admonition-title">Note</p>
  349. <p>The <a class="reference internal" href="#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> class uses the SGML syntactic rules for processing
  350. instructions. An XHTML processing instruction using the trailing <code class="docutils literal notranslate"><span class="pre">'?'</span></code> will
  351. cause the <code class="docutils literal notranslate"><span class="pre">'?'</span></code> to be included in <em>data</em>.</p>
  352. </div>
  353. </dd></dl>
  354. <dl class="py method">
  355. <dt class="sig sig-object py" id="html.parser.HTMLParser.unknown_decl">
  356. <span class="sig-prename descclassname"><span class="pre">HTMLParser.</span></span><span class="sig-name descname"><span class="pre">unknown_decl</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#html.parser.HTMLParser.unknown_decl" title="Link to this definition">¶</a></dt>
  357. <dd><p>This method is called when an unrecognized declaration is read by the parser.</p>
  358. <p>The <em>data</em> parameter will be the entire contents of the declaration inside
  359. the <code class="docutils literal notranslate"><span class="pre">&lt;![...]&gt;</span></code> markup. It is sometimes useful to be overridden by a
  360. derived class. The base class implementation does nothing.</p>
  361. </dd></dl>
  362. </section>
  363. <section id="examples">
  364. <span id="htmlparser-examples"></span><h2>Examples<a class="headerlink" href="#examples" title="Link to this heading">¶</a></h2>
  365. <p>The following class implements a parser that will be used to illustrate more
  366. examples:</p>
  367. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">html.parser</span> <span class="kn">import</span> <span class="n">HTMLParser</span>
  368. <span class="kn">from</span> <span class="nn">html.entities</span> <span class="kn">import</span> <span class="n">name2codepoint</span>
  369. <span class="k">class</span> <span class="nc">MyHTMLParser</span><span class="p">(</span><span class="n">HTMLParser</span><span class="p">):</span>
  370. <span class="k">def</span> <span class="nf">handle_starttag</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span> <span class="n">attrs</span><span class="p">):</span>
  371. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Start tag:&quot;</span><span class="p">,</span> <span class="n">tag</span><span class="p">)</span>
  372. <span class="k">for</span> <span class="n">attr</span> <span class="ow">in</span> <span class="n">attrs</span><span class="p">:</span>
  373. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot; attr:&quot;</span><span class="p">,</span> <span class="n">attr</span><span class="p">)</span>
  374. <span class="k">def</span> <span class="nf">handle_endtag</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tag</span><span class="p">):</span>
  375. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;End tag :&quot;</span><span class="p">,</span> <span class="n">tag</span><span class="p">)</span>
  376. <span class="k">def</span> <span class="nf">handle_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
  377. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Data :&quot;</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
  378. <span class="k">def</span> <span class="nf">handle_comment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
  379. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Comment :&quot;</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
  380. <span class="k">def</span> <span class="nf">handle_entityref</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
  381. <span class="n">c</span> <span class="o">=</span> <span class="nb">chr</span><span class="p">(</span><span class="n">name2codepoint</span><span class="p">[</span><span class="n">name</span><span class="p">])</span>
  382. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Named ent:&quot;</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span>
  383. <span class="k">def</span> <span class="nf">handle_charref</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
  384. <span class="k">if</span> <span class="n">name</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">):</span>
  385. <span class="n">c</span> <span class="o">=</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">name</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="mi">16</span><span class="p">))</span>
  386. <span class="k">else</span><span class="p">:</span>
  387. <span class="n">c</span> <span class="o">=</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
  388. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Num ent :&quot;</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span>
  389. <span class="k">def</span> <span class="nf">handle_decl</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
  390. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Decl :&quot;</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
  391. <span class="n">parser</span> <span class="o">=</span> <span class="n">MyHTMLParser</span><span class="p">()</span>
  392. </pre></div>
  393. </div>
  394. <p>Parsing a doctype:</p>
  395. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">parser</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="s1">&#39;&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &#39;</span>
  396. <span class="gp">... </span> <span class="s1">&#39;&quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;&#39;</span><span class="p">)</span>
  397. <span class="go">Decl : DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;</span>
  398. </pre></div>
  399. </div>
  400. <p>Parsing an element with a few attributes and a title:</p>
  401. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">parser</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="s1">&#39;&lt;img src=&quot;python-logo.png&quot; alt=&quot;The Python logo&quot;&gt;&#39;</span><span class="p">)</span>
  402. <span class="go">Start tag: img</span>
  403. <span class="go"> attr: (&#39;src&#39;, &#39;python-logo.png&#39;)</span>
  404. <span class="go"> attr: (&#39;alt&#39;, &#39;The Python logo&#39;)</span>
  405. <span class="gp">&gt;&gt;&gt;</span>
  406. <span class="gp">&gt;&gt;&gt; </span><span class="n">parser</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="s1">&#39;&lt;h1&gt;Python&lt;/h1&gt;&#39;</span><span class="p">)</span>
  407. <span class="go">Start tag: h1</span>
  408. <span class="go">Data : Python</span>
  409. <span class="go">End tag : h1</span>
  410. </pre></div>
  411. </div>
  412. <p>The content of <code class="docutils literal notranslate"><span class="pre">script</span></code> and <code class="docutils literal notranslate"><span class="pre">style</span></code> elements is returned as is, without
  413. further parsing:</p>
  414. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">parser</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="s1">&#39;&lt;style type=&quot;text/css&quot;&gt;#python { color: green }&lt;/style&gt;&#39;</span><span class="p">)</span>
  415. <span class="go">Start tag: style</span>
  416. <span class="go"> attr: (&#39;type&#39;, &#39;text/css&#39;)</span>
  417. <span class="go">Data : #python { color: green }</span>
  418. <span class="go">End tag : style</span>
  419. <span class="gp">&gt;&gt;&gt; </span><span class="n">parser</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="s1">&#39;&lt;script type=&quot;text/javascript&quot;&gt;&#39;</span>
  420. <span class="gp">... </span> <span class="s1">&#39;alert(&quot;&lt;strong&gt;hello!&lt;/strong&gt;&quot;);&lt;/script&gt;&#39;</span><span class="p">)</span>
  421. <span class="go">Start tag: script</span>
  422. <span class="go"> attr: (&#39;type&#39;, &#39;text/javascript&#39;)</span>
  423. <span class="go">Data : alert(&quot;&lt;strong&gt;hello!&lt;/strong&gt;&quot;);</span>
  424. <span class="go">End tag : script</span>
  425. </pre></div>
  426. </div>
  427. <p>Parsing comments:</p>
  428. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">parser</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="s1">&#39;&lt;!-- a comment --&gt;&#39;</span>
  429. <span class="gp">... </span> <span class="s1">&#39;&lt;!--[if IE 9]&gt;IE-specific content&lt;![endif]--&gt;&#39;</span><span class="p">)</span>
  430. <span class="go">Comment : a comment</span>
  431. <span class="go">Comment : [if IE 9]&gt;IE-specific content&lt;![endif]</span>
  432. </pre></div>
  433. </div>
  434. <p>Parsing named and numeric character references and converting them to the
  435. correct char (note: these 3 references are all equivalent to <code class="docutils literal notranslate"><span class="pre">'&gt;'</span></code>):</p>
  436. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">parser</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="s1">&#39;&amp;gt;&amp;#62;&amp;#x3E;&#39;</span><span class="p">)</span>
  437. <span class="go">Named ent: &gt;</span>
  438. <span class="go">Num ent : &gt;</span>
  439. <span class="go">Num ent : &gt;</span>
  440. </pre></div>
  441. </div>
  442. <p>Feeding incomplete chunks to <a class="reference internal" href="#html.parser.HTMLParser.feed" title="html.parser.HTMLParser.feed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">feed()</span></code></a> works, but
  443. <a class="reference internal" href="#html.parser.HTMLParser.handle_data" title="html.parser.HTMLParser.handle_data"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_data()</span></code></a> might be called more than once
  444. (unless <em>convert_charrefs</em> is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>):</p>
  445. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">chunk</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;&lt;sp&#39;</span><span class="p">,</span> <span class="s1">&#39;an&gt;buff&#39;</span><span class="p">,</span> <span class="s1">&#39;ered &#39;</span><span class="p">,</span> <span class="s1">&#39;text&lt;/s&#39;</span><span class="p">,</span> <span class="s1">&#39;pan&gt;&#39;</span><span class="p">]:</span>
  446. <span class="gp">... </span> <span class="n">parser</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="n">chunk</span><span class="p">)</span>
  447. <span class="gp">...</span>
  448. <span class="go">Start tag: span</span>
  449. <span class="go">Data : buff</span>
  450. <span class="go">Data : ered</span>
  451. <span class="go">Data : text</span>
  452. <span class="go">End tag : span</span>
  453. </pre></div>
  454. </div>
  455. <p>Parsing invalid HTML (e.g. unquoted attributes) also works:</p>
  456. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">parser</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="s1">&#39;&lt;p&gt;&lt;a class=link href=#main&gt;tag soup&lt;/p &gt;&lt;/a&gt;&#39;</span><span class="p">)</span>
  457. <span class="go">Start tag: p</span>
  458. <span class="go">Start tag: a</span>
  459. <span class="go"> attr: (&#39;class&#39;, &#39;link&#39;)</span>
  460. <span class="go"> attr: (&#39;href&#39;, &#39;#main&#39;)</span>
  461. <span class="go">Data : tag soup</span>
  462. <span class="go">End tag : p</span>
  463. <span class="go">End tag : a</span>
  464. </pre></div>
  465. </div>
  466. </section>
  467. </section>
  468. <div class="clearer"></div>
  469. </div>
  470. </div>
  471. </div>
  472. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  473. <div class="sphinxsidebarwrapper">
  474. <div>
  475. <h3><a href="../contents.html">Table of Contents</a></h3>
  476. <ul>
  477. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">html.parser</span></code> — Simple HTML and XHTML parser</a><ul>
  478. <li><a class="reference internal" href="#example-html-parser-application">Example HTML Parser Application</a></li>
  479. <li><a class="reference internal" href="#htmlparser-methods"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code> Methods</a></li>
  480. <li><a class="reference internal" href="#examples">Examples</a></li>
  481. </ul>
  482. </li>
  483. </ul>
  484. </div>
  485. <div>
  486. <h4>Previous topic</h4>
  487. <p class="topless"><a href="html.html"
  488. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">html</span></code> — HyperText Markup Language support</a></p>
  489. </div>
  490. <div>
  491. <h4>Next topic</h4>
  492. <p class="topless"><a href="html.entities.html"
  493. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">html.entities</span></code> — Definitions of HTML general entities</a></p>
  494. </div>
  495. <div role="note" aria-label="source link">
  496. <h3>This Page</h3>
  497. <ul class="this-page-menu">
  498. <li><a href="../bugs.html">Report a Bug</a></li>
  499. <li>
  500. <a href="https://github.com/python/cpython/blob/main/Doc/library/html.parser.rst"
  501. rel="nofollow">Show Source
  502. </a>
  503. </li>
  504. </ul>
  505. </div>
  506. </div>
  507. <div id="sidebarbutton" title="Collapse sidebar">
  508. <span>«</span>
  509. </div>
  510. </div>
  511. <div class="clearer"></div>
  512. </div>
  513. <div class="related" role="navigation" aria-label="related navigation">
  514. <h3>Navigation</h3>
  515. <ul>
  516. <li class="right" style="margin-right: 10px">
  517. <a href="../genindex.html" title="General Index"
  518. >index</a></li>
  519. <li class="right" >
  520. <a href="../py-modindex.html" title="Python Module Index"
  521. >modules</a> |</li>
  522. <li class="right" >
  523. <a href="html.entities.html" title="html.entities — Definitions of HTML general entities"
  524. >next</a> |</li>
  525. <li class="right" >
  526. <a href="html.html" title="html — HyperText Markup Language support"
  527. >previous</a> |</li>
  528. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  529. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  530. <li class="switchers">
  531. <div class="language_switcher_placeholder"></div>
  532. <div class="version_switcher_placeholder"></div>
  533. </li>
  534. <li>
  535. </li>
  536. <li id="cpython-language-and-version">
  537. <a href="../index.html">3.12.3 Documentation</a> &#187;
  538. </li>
  539. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  540. <li class="nav-item nav-item-2"><a href="markup.html" >Structured Markup Processing Tools</a> &#187;</li>
  541. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">html.parser</span></code> — Simple HTML and XHTML parser</a></li>
  542. <li class="right">
  543. <div class="inline-search" role="search">
  544. <form class="inline-search" action="../search.html" method="get">
  545. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  546. <input type="submit" value="Go" />
  547. </form>
  548. </div>
  549. |
  550. </li>
  551. <li class="right">
  552. <label class="theme-selector-label">
  553. Theme
  554. <select class="theme-selector" oninput="activateTheme(this.value)">
  555. <option value="auto" selected>Auto</option>
  556. <option value="light">Light</option>
  557. <option value="dark">Dark</option>
  558. </select>
  559. </label> |</li>
  560. </ul>
  561. </div>
  562. <div class="footer">
  563. &copy;
  564. <a href="../copyright.html">
  565. Copyright
  566. </a>
  567. 2001-2024, Python Software Foundation.
  568. <br />
  569. This page is licensed under the Python Software Foundation License Version 2.
  570. <br />
  571. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  572. <br />
  573. See <a href="/license.html">History and License</a> for more information.<br />
  574. <br />
  575. The Python Software Foundation is a non-profit corporation.
  576. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  577. <br />
  578. <br />
  579. Last updated on Apr 09, 2024 (13:47 UTC).
  580. <a href="/bugs.html">Found a bug</a>?
  581. <br />
  582. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  583. </div>
  584. </body>
  585. </html>
上海开阖软件有限公司 沪ICP备12045867号-1