Skip to main content

collective.soupstrainer

Quite often there is a need to clean up HTML from some source, be it user input or data gathered by scraping, which needs to be cleaned up. With the SoupStrainer class in collective.soupstrainer this is made easy. It uses beautifulsoup4 to parse and clean up HTML. The constructor of the class takes four arguments.

exclusions

This is a list of tuples with two items each. The first item is a list of tag names, the second item is a list of attributes. If the list of attributes is empty, then each tag in the first list is completely removed from the passed in HTML. If the list of tags is empty, then each attribute listed is completely removed. If there are both tags and attributes listed, then the attributes are only removed from matching tags.

style_whitelist

This is a white list of CSS styles allowed in ‘style’ attributes. All other styles are removed.

class_blacklist

This is a black list for CSS classes. Each matching class is removed from ‘class’ attributes.

parser

This is the parser used by beautifulsoup4, when the strainer is called with a string. It must be an installed parser for beautifulsoup4, defaults to html.parser

An instance of the SoupStrainer class can be called directly with one argument. The argument can either be a string, in which case it will internally be parsed by beautifulsoup4 and the result will be unicode (or string in python 3), or it can be a parsed HTML tree created by beautifulsoup4, in which case it will be modified in place and be returned again.

Changelog

2.2 (2021-03-25)

  • Do not stop after the first replace of a tag which is to be excluded. (#8)

  • Add support for Python 3.8 and 3.9.

2.1 (2019-02-06)

  • Add support for Python 3 and PyPy.

2.0 (2017-10-19)

Backwards incompatible changes

  • Update to beautifulsoup4.

  • Add a parameter parser to SoupStrainer which specifies the parser used by beautifulsoup4.

1.0 - 2008-11-14

  • Initial release

Release files for collective.soupstrainer 2.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 collective.soupstrainer 2.2
File Size Uploaded
collective.soupstrainer-2.2.tar.gz 10.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for collective.soupstrainer 2.2
File Interpreter ABI Platform
collective.soupstrainer-2.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 16.2 kB

Release files / collective.soupstrainer-2.2.tar.gz

Download URL collective.soupstrainer-2.2.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f10cb82543ee4c194abfc64c4783e1192b04fb5807382da10c511716715873ff
BLAKE2b-256 checksum
How to use checksums
399d6837ea22da3c285518bae2aa839c9fde15104fded108851638e5319e819f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/None requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.10

Release files / collective.soupstrainer-2.2-py2.py3-none-any.whl

Download URL collective.soupstrainer-2.2-py2.py3-none-any.whl
Size 5.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b9d6dea2c2fd8649701a277f7a4bb6427cb35a3e9350b52915b2d209442b2879
BLAKE2b-256 checksum
How to use checksums
3ca182d584ccc90d860a4d49dd07db18bbde21abb9c50779b147ee1e2966bbed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/None requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.10

Release history Release notifications | RSS feed

This release

2.2 This release

2 release files

2.1

1 release file

2.0

1 release file

1.0

1 release file

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