Skip to main content

a html parser based lxml

Project description

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>
"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lxmlHtml-0.0.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

lxmlHtml-0.0.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file lxmlHtml-0.0.2.tar.gz.

File metadata

  • Download URL: lxmlHtml-0.0.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for lxmlHtml-0.0.2.tar.gz
Algorithm Hash digest
SHA256 be004cd74860bd40fee5cb4747bef654ccfdcddbda55fbce9a048f2f72d9f4c8
MD5 dad26acad8ce6b5a0e2f5db0a6e86a02
BLAKE2b-256 abc5381006df4f5d06d29825fdaf827a59a5afc20203da3f14008db7da521ff5

See more details on using hashes here.

File details

Details for the file lxmlHtml-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: lxmlHtml-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for lxmlHtml-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6407ac58a2b08d228aedecc203bc31b2d2f5318f3d288c1d33bd10d4fa044dd2
MD5 ef2d21eef25ddece036c38a0f4880e5e
BLAKE2b-256 d18db23f0d17f863014b028cb1da45fcbfd043f43b7f0cec2d8eb6a3fe271c2c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page