Is there any way I can control the depth of unwrapping? My HTML's sometimes contain css. And prettify adds newline to every tag...
<html><body><h1>hello world</h1></body></html>
to:
<html>
<body><h1>hello world</h1></body>
</html>
from bs4 import BeautifulSoup
INPUT_FILE = "html_unformatted.txt"
OUTPUT_FILE = "index.html"
unicode_data = open(INPUT_FILE, "r", encoding='unicode_escape').read()
data = unicode_data.encode('iso-8859-1').decode('utf-8')
soup = BeautifulSoup(data, features="html.parser")
pretty_html = soup.prettify()
with open(OUTPUT_FILE, "w") as f:
f.write(pretty_html)
print(f"Wrote to {OUTPUT_FILE}")
I have:
<html>
<body>
<h1>
hello world
</h1>
</body>
</html>