import re from pathlib import Path # текущая папка (где лежит скрипт) ROOT_DIR = Path(".").resolve() pattern = re.compile( r"
\s*" r"\s*" r"\s*" r"\s*" r"
", re.DOTALL ) extensions = {".html", ".htm", ".php"} for file in ROOT_DIR.rglob("*"): if file.suffix.lower() in extensions: try: text = file.read_text(encoding="utf-8", errors="ignore") new_text, count = pattern.subn("", text) if count > 0: file.write_text(new_text, encoding="utf-8") print(f"cleaned: {file}") except Exception as e: print(f"error: {file} -> {e}") print("done")