def clean_dir(directory):
    os.chdir(directory)
for filename in os.listdir(directory):
    clean_file(filename)

def clean_file(filename):
    tag_black_list = ['iframe', 'script']
tag_white_list = ['p', 'div']
attr_white_list = {'*': ['title']}
with open(filename, 'r') as fhandle:
    text = BeautifulSoup(fhandle)
text.encode('utf-8')
[s.decompose() for s in text(tag_black_list)]
pretty = text.prettify()
cleaned = bleach.clean(pretty, strip='TRUE', attributes=attr_white_list,
    tags=tag_white_list)
dot_pos = filename.rfind('.')
cleaned_filename = '{0}-cleaned{1}'.format(filename[:dot_pos], filename[
    dot_pos:])
with open(cleaned_filename, 'w') as fout:
    fout.write(cleaned.encode('utf-8'))
print('Done')
Parse each file in a directory with BeautifulSoup/Python, save out as new file