Skip to main content

axe Chopper

pypi github-actions readthedocs

Chopper is a tool to extract elements from HTML by preserving ancestors and CSS rules.

Compatible with Python >= 3.8

Installation

pip install chopper

Full documentation

http://chopper.readthedocs.org/en/latest/

Quick start

from chopper.extractor import Extractor

HTML = """
<html>
  <head>
    <title>Test</title>
  </head>
  <body>
    <div id="header"></div>
    <div id="main">
      <div class="iwantthis">
        HELLO WORLD
        <a href="/nope">Do not want</a>
      </div>
    </div>
    <div id="footer"></div>
  </body>
</html>
"""

CSS = """
div { border: 1px solid black; }
div#main { color: blue; }
div.iwantthis { background-color: red; }
a { color: green; }
div#footer { border-top: 2px solid red; }
"""

extractor = Extractor.keep('//div[@class="iwantthis"]').discard('//a')
html, css = extractor.extract(HTML, CSS)

The result is :

>>> html
"""
<html>
  <body>
    <div id="main">
      <div class="iwantthis">
        HELLO WORLD
      </div>
    </div>
  </body>
</html>"""

>>> css
"""
div{border:1px solid black;}
div#main{color:blue;}
div.iwantthis{background-color:red;}
"""

Metadata

Release files for chopper 0.6.0

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

Source distribution (sdist)

Source distribution for chopper 0.6.0
File Size Uploaded
chopper-0.6.0.linux-x86_64.tar.gz 22.6 kB Details

Built distribution (wheel)

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

Total release size: 39.0 kB

Release files / chopper-0.6.0.linux-x86_64.tar.gz

Download URL chopper-0.6.0.linux-x86_64.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1d80edbdbe1775e678c548b548e47f3865f3c21db73d65113fd54e985570d301
BLAKE2b-256 checksum
How to use checksums
50b9f85a586995dedd16998408d08e07c6c5b6cb2c65cdebc5f7d248faf95240
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / chopper-0.6.0-py3-none-any.whl

Download URL chopper-0.6.0-py3-none-any.whl
Size 16.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
662f87c1922c5661c4560c7b770fb7e59fcc846fe29b0911f865dc80ef664e6e
BLAKE2b-256 checksum
How to use checksums
9b9db361aa78acb0ea02e456db57e9988a064b527ecd9c266a51ee1ef2f462fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.8

1 release file

0.4.7

2 release files

0.4.6

1 release file

0.4.5

1 release file

0.4.4

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.10

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