So i have a bunch of HTML files that i would like to fix the markup on with the help of bs4. But once i run the code, all files are just empty (lucky my i made a backup before running my script on the folder).
This is what i have so far:
from bs4 import BeautifulSoup
import os
for entry in os.scandir(path):
if entry.is_file() and entry.path.endswith('html'):
file = open(entry.path, 'w+')
soup = BeautifulSoup(file, 'html.parser')
file.write(soup.prettify())
print(colored('Success', 'green'))
file.close()
The expected result would be that the file is read, prettyfied and saved.