Sunday, 15 July 2012

python - Shortening HTML files -



python - Shortening HTML files -

is there library (preferably python one) shortens html page? mean produce perchance smaller (in terms of number of characters, including line breaks <- think length of string) html page rendered same original one?

for instance:

<b> silly illustration </b>

could changed to:

<b>silly example</b>

and final result same:

silly example

you can utilize beautifulsoup prettify (not minify) html or xml code in python.

from bs4 import beautifulsoup soup = beautifulsoup('file.html') prettified = soup.prettify(encoding="utf8")

for minifying html in python can utilize htmlmin. more parameters htmlmin.minify can found in documentation.

import htmlmin open('file.html', 'r') f: content = f.read() minified = htmlmin.minify(content, remove_empty_space=true)

python html

No comments:

Post a Comment