Skip to main content

lxml-html

a html parser based lxml

Element is a wrapper of lxml.html.HtmlElement

Element implement a proxy of HtmlElement

install

pip install lxmlHtml

quick start

from lxmlHtml import Element

text = """
<div>
    <span></span>
    <span></span>
    <span></span>
</div>
"""
element = Element.fragment_fromstring(text)

# add some attribute
first_span = element.cssselect('span')[0]
print(first_span)

first_span.set('width', '200px')
first_span.styles.set('font-size', '20px')
first_span.styles.set('max-width', '200px')
first_span.classes.add('red')
first_span.classes.add('green')

# remove element
element.xpath_first('//span[2]').drop_tag()

# # get children
print(element.getchildren())

# # add element
last_span = element.xpath_first("//span[last()]")
print(last_span)

ele = element.makeelement("p")
c = element.makecomment("p")
last_span.append(ele)
last_span.append(c)

# serialize
print(element.tostring(pretty_print=True))
"""
<div>
    <span width="200px" style="font-size: 20px; max-width: 200px;" class="red green"></span>

    <span><p></p>
<!--p--></span>
</div>
"""

Metadata

Release files for lxmlHtml 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lxmlHtml 0.0.2
File Size Uploaded
lxmlHtml-0.0.2.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lxmlHtml 0.0.2
File Interpreter ABI Platform
lxmlHtml-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.0 kB

Release files / lxmlHtml-0.0.2.tar.gz

Download URL lxmlHtml-0.0.2.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
be004cd74860bd40fee5cb4747bef654ccfdcddbda55fbce9a048f2f72d9f4c8
BLAKE2b-256 checksum
How to use checksums
abc5381006df4f5d06d29825fdaf827a59a5afc20203da3f14008db7da521ff5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.0

Release files / lxmlHtml-0.0.2-py3-none-any.whl

Download URL lxmlHtml-0.0.2-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6407ac58a2b08d228aedecc203bc31b2d2f5318f3d288c1d33bd10d4fa044dd2
BLAKE2b-256 checksum
How to use checksums
d18db23f0d17f863014b028cb1da45fcbfd043f43b7f0cec2d8eb6a3fe271c2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page