1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| import re
path = "D:/11"
def listdir(dir):
filenames = os.listdir(dir)
for files in filenames:
print(files)
listdir(path)
extensie_fisier = ".html"
regexes = {
r'<title>.*\|\K(.*)(</title>)': r'Bebe', # First regex r'regex1': r'string1'
r'^<html.*$': r'fff' # Second regex r'regex1': r'string1'
}
for k, v in regexes.items():
print(re.sub(k, v, 'text'))
with open("*.html", mode="w") as file: # See note 2.
contents = file.write(f"{extensie_fisier.text}")
print("DONE !") |
Partager