Boned html is a small python library.
It helps you extract text from an html (in the form of a lxml tree), process this text, to classify it, reinject text in the html with specific css classes.
The typical use is for anotating an html with classes. For example you are categorizing text, and you want the user to visualize those categories on the original html.
The text will be extracted in a smart way: it won’t stop at semantic tags (<i>, <em>, etc.) but at other tags (<h1>, <p>, etc.).
As you reinject the text, semantic tags will be added back to text, and general html layout will be respected.
Installation
pip install boned-html
Usage
The fonctionalities are provided by the class boned_html.Chunker with methods:
chunk_tree to get text chunks from an lxml tree.
unchunk to put back chunks together providing css classes for pieces of text.
A quick example: imagine we have a function to detect a tel number value in a sentence:
>>> import re
>>> from itertools import cycle
>>> def get_tel(text):
... splits = re.split(r"(\+?(?:\d\s*){8,13})", text)
... return list(zip(splits, cycle([None, "tel"])))
>>> get_tel("call +33 00 00 00 00")
[('call ', None), ('+33 00 00 00 00', 'tel'), ('', None)]
And an html:
>>> html = ''' ... <html> ... <head><title>call +33 00 00 00 00</title></head> ... <body> ... <p>To get an operator <em>call</em></p> ... <p><b>call</b> <em>(country) +33</em> 00 00 00 00</p> ... </body> ... </html> ... '''
We chunk:
>>> import lxml.html >>> from boned_html import HtmlBoner >>> tree = lxml.html.fromstring(html) >>> boned = HtmlBoner(tree)
We evaluate each text and assign “tel” class to it if there is a telephone:
>>> for i, text in enumerate(boned): ... if text is not None: ... boned.set_classes(i, get_tel(text))
We now rebuild the tree:
>>> boned.tree
<Element html ...>
>>> print(boned)
<html>
<head><title>call +33 00 00 00 00</title></head>
<body>
<p>To get an operator <em>call</em></p>
<p><b>call</b> <em>(country) </em><span class="tel" id="chunk-6-1"><em>+33</em> 00 00 00 00</span></p>
</body>
</html>
We have a specific span around our number, also opening and closure of em tag was handled, and phone number in head/title remains the same.
Metadata
Release files for boned-html 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| boned-html-0.2.tar.gz | 10.9 kB | Without provenance | Details for boned-html-0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| boned_html-0.2-py3-none-any.whl | Python 3 | none | any | Details for boned_html-0.2-py3-none-any.whl |
Total release size: 23.9 kB
Release files / boned-html-0.2.tar.gz
| Download URL | boned-html-0.2.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
69b1e42a3ef14217b531c47635b355cdeddd716684af1da2d284d4649cf4caff
|
|
BLAKE2b-256 checksum How to use checksums |
9ae2d54fb05a126bbb6047a7062206aa3fa773b204ce3e982e29afbf46cd8d7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / boned_html-0.2-py3-none-any.whl
| Download URL | boned_html-0.2-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e75ba1ebfd018660f9ac9dc12f0fe8e3a8ce84b840add48c92cb98748c82de9b
|
|
BLAKE2b-256 checksum How to use checksums |
5e543252b547ac81f7933be843b62432e7a8a6bd83ed05652d98860a97cee53b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for boned-html 0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.