Skip to main content

Lib to extract html elements by preserving ancestors and cleaning CSS

Project description

pypi travis coveralls

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

Compatible with Python >= 2.6, <= 3.4

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

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

chopper-0.4.7.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

chopper-0.4.7-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file chopper-0.4.7.tar.gz.

File metadata

  • Download URL: chopper-0.4.7.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for chopper-0.4.7.tar.gz
Algorithm Hash digest
SHA256 bf3c15e9ef00ce3b7fb88538aeab51239a1787529a107dffd914dd4c8ac2eda8
MD5 7cc438f09f406cb9b27bd5e0c65907ac
BLAKE2b-256 da176ed7e1ff33a9a20d3ae42ca1bf7eea406b5f9dc0249b23137c9c004d0630

See more details on using hashes here.

File details

Details for the file chopper-0.4.7-py3-none-any.whl.

File metadata

File hashes

Hashes for chopper-0.4.7-py3-none-any.whl
Algorithm Hash digest
SHA256 601716c1d0844ec196c78f77d12dc98eb4f771bffe556bb6b65b26c92804cfe9
MD5 6cee2d59b9701d082f79eef2d2576e2a
BLAKE2b-256 cf56d05fd1931d7c529794bd51d2c992e0a540cfe4c0772efabd07cc1e736519

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