Skip to main content
<h1>Python HTML purifier</h1>

<h2>About</h2>

<p>Cuts the tags and attributes from HTML that are not in the whitelist.
Their content is leaves. Signature of whitelist:
<code>python
{
'enabled tag name' : ['list of enabled tag\'s attributes']
}
</code>
You can use the symbol <code>*</code> to allow all tags and/or attributes.</p>

<p>Note that the <code>script</code> and <code>style</code> tags are removed with content.</p>

<p>The module is based on
<a href="http://docs.python.org/2/library/htmlparser.html">HTMLParser</a>
Class - in the standard Python package.
No need to pull a dependence, what is also sometimes can be a plus.</p>

<p><a href="http://pixxxxxel.blogspot.ru/2013/07/html-purifier-python.html">In my blog</a></p>

<h2>Basic Use</h2>

<p>```python</p>

<blockquote>
<blockquote>
<blockquote>
<p>purifier = HTMLPurifier({
'div': ['*'], # разрешает все атрибуты у тега div
'span': ['attr-2'], # разрешает только атрибут attr-2 у тега span
# все остальные теги удаляются, но их содержимое остается
})
print purifier.feed('<div class="e1" id="e1">Some <b>HTML</b> for <span attr-1="1" attr-2="2">purifying</span></div>')</p>
</blockquote>
</blockquote>
</blockquote>

<div class="e1" id="e1">Some HTML for <span attr-2="2">purifying</span></div>

<p>```</p>

Download files

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

Source Distribution

html-purifier-0.1.2.zip (87.1 kB view details)

Uploaded Source

File details

Details for the file html-purifier-0.1.2.zip.

File metadata

  • Download URL: html-purifier-0.1.2.zip
  • Upload date:
  • Size: 87.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for html-purifier-0.1.2.zip
Algorithm Hash digest
SHA256 2301cfecf617dd0c462eea8462a07bb58c7a4e4f7dba3897dd009724012d92ce
MD5 b4883ed0a2b7c378e01bc75fd58954b6
BLAKE2b-256 226c3ebebc8f8cd9dd4add3247990d5e39273d5a62c28882333842938ada97af

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.9

1 file

0.1.8

1 file

0.1.7

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

1 file

0.1.3

1 file

This release

0.1.2 This release

1 file

0.1.1

1 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