Is there a library (preferably a Python one) that shortens an HTML page? By that I mean that it will produce a possibly smaller (in terms of number of characters, including line breaks <- think about the length of a string) HTML page that is rendered exactly the same as the original one?
You can use BeautifulSoup to prettify (not minify) HTML or XML code in Python.
from bs4 import BeautifulSoup soup = BeautifulSoup('file.html') prettified = soup.prettify(encoding="utf8")
import htmlmin with open('file.html', 'r') as f: content = f.read() minified = htmlmin.minify(content, remove_empty_space=True)