| 1 |
Metadata-Version: 2.1 |
| 2 |
Name: html5lib-modern |
| 3 |
Version: 1.2 |
| 4 |
Summary: HTML parser based on the WHATWG HTML specification |
| 5 |
Home-page: https://github.com/html5lib/html5lib-python |
| 6 |
Author-email: Ashley Sommer <[email protected]>, James Graham <[email protected]> |
| 7 |
Maintainer: James Graham |
| 8 |
Maintainer-email: [email protected] |
| 9 |
License: Copyright (c) 2006-2013 James Graham and other contributors |
| 10 |
|
| 11 |
Permission is hereby granted, free of charge, to any person obtaining |
| 12 |
a copy of this software and associated documentation files (the |
| 13 |
"Software"), to deal in the Software without restriction, including |
| 14 |
without limitation the rights to use, copy, modify, merge, publish, |
| 15 |
distribute, sublicense, and/or sell copies of the Software, and to |
| 16 |
permit persons to whom the Software is furnished to do so, subject to |
| 17 |
the following conditions: |
| 18 |
|
| 19 |
The above copyright notice and this permission notice shall be |
| 20 |
included in all copies or substantial portions of the Software. |
| 21 |
|
| 22 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 23 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 24 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 25 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 26 |
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 27 |
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 28 |
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 29 |
|
| 30 |
Classifier: Development Status :: 5 - Production/Stable |
| 31 |
Classifier: Intended Audience :: Developers |
| 32 |
Classifier: License :: OSI Approved :: MIT License |
| 33 |
Classifier: Operating System :: OS Independent |
| 34 |
Classifier: Programming Language :: Python |
| 35 |
Classifier: Programming Language :: Python :: 3 |
| 36 |
Classifier: Programming Language :: Python :: 3.8 |
| 37 |
Classifier: Programming Language :: Python :: 3.9 |
| 38 |
Classifier: Programming Language :: Python :: 3.10 |
| 39 |
Classifier: Programming Language :: Python :: 3.11 |
| 40 |
Classifier: Programming Language :: Python :: Implementation :: CPython |
| 41 |
Classifier: Programming Language :: Python :: Implementation :: PyPy |
| 42 |
Classifier: Topic :: Software Development :: Libraries :: Python Modules |
| 43 |
Classifier: Topic :: Text Processing :: Markup :: HTML |
| 44 |
Requires-Python: >=3.8 |
| 45 |
Description-Content-Type: text/x-rst |
| 46 |
License-File: LICENSE |
| 47 |
License-File: AUTHORS.rst |
| 48 |
Provides-Extra: lxml |
| 49 |
Requires-Dist: lxml>=3.4.0; platform_python_implementation == "CPython" and extra == "lxml" |
| 50 |
Provides-Extra: genshi |
| 51 |
Requires-Dist: genshi>=0.7.1; extra == "genshi" |
| 52 |
Provides-Extra: chardet |
| 53 |
Requires-Dist: chardet>=2.2.1; extra == "chardet" |
| 54 |
Provides-Extra: all |
| 55 |
Requires-Dist: genshi>=0.7.1; extra == "all" |
| 56 |
Requires-Dist: chardet>=2.2.1; extra == "all" |
| 57 |
Requires-Dist: lxml>=3.4.0; platform_python_implementation == "CPython" and extra == "all" |
| 58 |
|
| 59 |
html5lib |
| 60 |
======== |
| 61 |
|
| 62 |
.. image:: https://github.com/html5lib/html5lib-python/actions/workflows/python-tox.yml/badge.svg |
| 63 |
:target: https://github.com/html5lib/html5lib-python/actions/workflows/python-tox.yml |
| 64 |
|
| 65 |
html5lib is a pure-python library for parsing HTML. It is designed to |
| 66 |
conform to the WHATWG HTML specification, as is implemented by all major |
| 67 |
web browsers. |
| 68 |
|
| 69 |
|
| 70 |
Usage |
| 71 |
----- |
| 72 |
|
| 73 |
Simple usage follows this pattern: |
| 74 |
|
| 75 |
.. code-block:: python |
| 76 |
|
| 77 |
import html5lib |
| 78 |
with open("mydocument.html", "rb") as f: |
| 79 |
document = html5lib.parse(f) |
| 80 |
|
| 81 |
or: |
| 82 |
|
| 83 |
.. code-block:: python |
| 84 |
|
| 85 |
import html5lib |
| 86 |
document = html5lib.parse("<p>Hello World!") |
| 87 |
|
| 88 |
By default, the ``document`` will be an ``xml.etree`` element instance. |
| 89 |
Whenever possible, html5lib chooses the accelerated ``ElementTree`` |
| 90 |
implementation. |
| 91 |
|
| 92 |
Two other tree types are supported: ``xml.dom.minidom`` and |
| 93 |
``lxml.etree``. To use an alternative format, specify the name of |
| 94 |
a treebuilder: |
| 95 |
|
| 96 |
.. code-block:: python |
| 97 |
|
| 98 |
import html5lib |
| 99 |
with open("mydocument.html", "rb") as f: |
| 100 |
lxml_etree_document = html5lib.parse(f, treebuilder="lxml") |
| 101 |
|
| 102 |
When using with ``urllib.request`` (Python 3), the charset from HTTP |
| 103 |
should be pass into html5lib as follows: |
| 104 |
|
| 105 |
.. code-block:: python |
| 106 |
|
| 107 |
from urllib.request import urlopen |
| 108 |
import html5lib |
| 109 |
|
| 110 |
with urlopen("http://example.com/") as f: |
| 111 |
document = html5lib.parse(f, transport_encoding=f.info().get_content_charset()) |
| 112 |
|
| 113 |
To have more control over the parser, create a parser object explicitly. |
| 114 |
For instance, to make the parser raise exceptions on parse errors, use: |
| 115 |
|
| 116 |
.. code-block:: python |
| 117 |
|
| 118 |
import html5lib |
| 119 |
with open("mydocument.html", "rb") as f: |
| 120 |
parser = html5lib.HTMLParser(strict=True) |
| 121 |
document = parser.parse(f) |
| 122 |
|
| 123 |
When you're instantiating parser objects explicitly, pass a treebuilder |
| 124 |
class as the ``tree`` keyword argument to use an alternative document |
| 125 |
format: |
| 126 |
|
| 127 |
.. code-block:: python |
| 128 |
|
| 129 |
import html5lib |
| 130 |
parser = html5lib.HTMLParser(tree=html5lib.getTreeBuilder("dom")) |
| 131 |
minidom_document = parser.parse("<p>Hello World!") |
| 132 |
|
| 133 |
More documentation is available at https://html5lib.readthedocs.io/. |
| 134 |
|
| 135 |
|
| 136 |
Installation |
| 137 |
------------ |
| 138 |
|
| 139 |
html5lib works on CPython 3.8+ and PyPy. To install: |
| 140 |
|
| 141 |
.. code-block:: bash |
| 142 |
|
| 143 |
$ pip install html5lib |
| 144 |
|
| 145 |
The goal is to support a (non-strict) superset of the versions that `pip |
| 146 |
supports |
| 147 |
<https://pip.pypa.io/en/stable/installing/#python-and-os-compatibility>`_. |
| 148 |
|
| 149 |
Optional Dependencies |
| 150 |
--------------------- |
| 151 |
|
| 152 |
The following third-party libraries may be used for additional |
| 153 |
functionality: |
| 154 |
|
| 155 |
- ``lxml`` is supported as a tree format (for both building and |
| 156 |
walking) under CPython (but *not* PyPy where it is known to cause |
| 157 |
segfaults); |
| 158 |
|
| 159 |
- ``genshi`` has a treewalker (but not builder); and |
| 160 |
|
| 161 |
- ``chardet`` can be used as a fallback when character encoding cannot |
| 162 |
be determined. |
| 163 |
|
| 164 |
|
| 165 |
Bugs |
| 166 |
---- |
| 167 |
|
| 168 |
Please report any bugs on the `issue tracker |
| 169 |
<https://github.com/html5lib/html5lib-python/issues>`_. |
| 170 |
|
| 171 |
|
| 172 |
Tests |
| 173 |
----- |
| 174 |
|
| 175 |
Unit tests require the ``pytest`` and ``mock`` libraries and can be |
| 176 |
run using the ``pytest`` command in the root directory. |
| 177 |
|
| 178 |
Test data are contained in a separate `html5lib-tests |
| 179 |
<https://github.com/html5lib/html5lib-tests>`_ repository and included |
| 180 |
as a submodule, thus for git checkouts they must be initialized:: |
| 181 |
|
| 182 |
$ git submodule init |
| 183 |
$ git submodule update |
| 184 |
|
| 185 |
If you have all compatible Python implementations available on your |
| 186 |
system, you can run tests on all of them using the ``tox`` utility, |
| 187 |
which can be found on PyPI. |
| 188 |
|
| 189 |
|
| 190 |
Questions? |
| 191 |
---------- |
| 192 |
|
| 193 |
Check out `the docs <https://html5lib.readthedocs.io/en/latest/>`_. Still |
| 194 |
need help? Go to our `GitHub Discussions |
| 195 |
<https://github.com/html5lib/html5lib-python/discussions>`_. |
| 196 |
|
| 197 |
You can also browse the archives of the `html5lib-discuss mailing list |
| 198 |
<https://www.mail-archive.com/[email protected]/>`_. |
| 199 |
|
| 200 |
Credits |
| 201 |
======= |
| 202 |
|
| 203 |
``html5lib`` is written and maintained by: |
| 204 |
|
| 205 |
- James Graham |
| 206 |
- Sam Sneddon |
| 207 |
- Łukasz Langa |
| 208 |
- Will Kahn-Greene |
| 209 |
|
| 210 |
|
| 211 |
Patches and suggestions |
| 212 |
----------------------- |
| 213 |
(In chronological order, by first commit:) |
| 214 |
|
| 215 |
- Anne van Kesteren |
| 216 |
- Lachlan Hunt |
| 217 |
- lantis63 |
| 218 |
- Sam Ruby |
| 219 |
- Thomas Broyer |
| 220 |
- Tim Fletcher |
| 221 |
- Mark Pilgrim |
| 222 |
- Ryan King |
| 223 |
- Philip Taylor |
| 224 |
- Edward Z. Yang |
| 225 |
- fantasai |
| 226 |
- Philip Jägenstedt |
| 227 |
- Ms2ger |
| 228 |
- Mohammad Taha Jahangir |
| 229 |
- Andy Wingo |
| 230 |
- Andreas Madsack |
| 231 |
- Karim Valiev |
| 232 |
- Juan Carlos Garcia Segovia |
| 233 |
- Mike West |
| 234 |
- Marc DM |
| 235 |
- Simon Sapin |
| 236 |
- Michael[tm] Smith |
| 237 |
- Ritwik Gupta |
| 238 |
- Marc Abramowitz |
| 239 |
- Tony Lopes |
| 240 |
- lilbludevil |
| 241 |
- Kevin |
| 242 |
- Drew Hubl |
| 243 |
- Austin Kumbera |
| 244 |
- Jim Baker |
| 245 |
- Jon Dufresne |
| 246 |
- Donald Stufft |
| 247 |
- Alex Gaynor |
| 248 |
- Nik Nyby |
| 249 |
- Jakub Wilk |
| 250 |
- Sigmund Cherem |
| 251 |
- Gabi Davar |
| 252 |
- Florian Mounier |
| 253 |
- neumond |
| 254 |
- Vitalik Verhovodov |
| 255 |
- Kovid Goyal |
| 256 |
- Adam Chainz |
| 257 |
- John Vandenberg |
| 258 |
- Eric Amorde |
| 259 |
- Benedikt Morbach |
| 260 |
- Jonathan Vanasco |
| 261 |
- Tom Most |
| 262 |
- Ville Skyttä |
| 263 |
- Hugo van Kemenade |
| 264 |
- Mark Vasilkov |
| 265 |
|
| 266 |
|
| 267 |
HTML5Lib-modern |
| 268 |
--------------- |
| 269 |
|
| 270 |
- Ashley Sommer |