This script is an automated HTML cleaner designed to optimize web content for SEO, specifically tailored for HTML code generated by Blogger image uploads.
By removing inline style attributes, CSS style blocks, and class parameters, it cleans clutter to improve the code-to-text ratio, enhancing page loading speed-a key ranking factor.It strips anchor tags while preserving their internal content, eliminating unwanted external links or internal link equity leaks.By keeping only structural tags like div and img, it produces lightweight, clean HTML markup that search engine crawlers can index and parse easily.

Let's see the source code:
import tkinter as tk
from tkinter import ttk, messagebox
from bs4 import BeautifulSoup
def paste_from_clipboard():
try:
text_input.insert(tk.INSERT, root.clipboard_get())
except Exception:
try:
text_input.focus_set()
text_input.event_generate("<<Paste>>")
except Exception:
pass
def process_html():
raw_html = text_input.get("1.0", tk.END).strip()
if not raw_html:
return
try:
soup = BeautifulSoup(raw_html, "html.parser")
# 1. Eliminare completă tag-uri style și script
for tag in soup.find_all(["style", "script"]):
tag.decompose()
# 2. Eliminare ancore (<a>) și păstrare conținut
for a_tag in soup.find_all("a"):
a_tag.unwrap()
# 3. Eliminare atribute 'style' și 'class' de pe TOATE elementele
attributes_to_remove = ["style", "class"]
for tag in soup.find_all(True):
for attr in attributes_to_remove:
if attr in tag.attrs:
del tag.attrs[attr]
cleaned_html = str(soup)
text_output.config(state=tk.NORMAL)
text_output.delete("1.0", tk.END)
text_output.insert(tk.END, cleaned_html)
text_output.config(state=tk.DISABLED)
except Exception as e:
messagebox.showerror("Eroare", f"A aparut o eroare la procesare: {e}")
def copy_to_clipboard():
cleaned_text = text_output.get("1.0", tk.END).strip()
if cleaned_text:
try:
root.clipboard_clear()
root.clipboard_append(cleaned_text)
messagebox.showinfo("OK", "Copiat in clipboard!")
except Exception as e:
messagebox.showerror("Eroare", f"Nu s-a putut copia: {e}")
def clear_all():
text_input.delete("1.0", tk.END)
text_output.config(state=tk.NORMAL)
text_output.delete("1.0", tk.END)
text_output.config(state=tk.DISABLED)
# Constructie Interfata
root = tk.Tk()
root.title("HTML Cleaner")
root.geometry("400x600")
# Input
lbl1 = ttk.Label(root, text="1. Sursa HTML:")
lbl1.pack(anchor="w", padx=10, pady=(10, 0))
frame_btns = ttk.Frame(root)
frame_btns.pack(fill=tk.X, padx=10, pady=5)
btn_paste = ttk.Button(frame_btns, text="Lipeste (Paste)", command=paste_from_clipboard)
btn_paste.pack(side=tk.LEFT, fill=tk.X, expand=True, padx=(0, 5))
btn_clear = ttk.Button(frame_btns, text="Sterge", command=clear_all)
btn_clear.pack(side=tk.RIGHT)
text_input = tk.Text(root, height=8)
text_input.pack(fill=tk.BOTH, expand=True, padx=10, pady=5)
# Procesare
btn_process = ttk.Button(root, text="Proceseaza HTML", command=process_html)
btn_process.pack(fill=tk.X, padx=10, pady=5)
# Output
lbl2 = ttk.Label(root, text="2. Rezultat Curatat:")
lbl2.pack(anchor="w", padx=10, pady=(5, 0))
text_output = tk.Text(root, height=8, state=tk.DISABLED)
text_output.pack(fill=tk.BOTH, expand=True, padx=10, pady=5)
btn_copy = ttk.Button(root, text="Copiaza Rezultatul", command=copy_to_clipboard)
btn_copy.pack(fill=tk.X, padx=10, pady=(5, 10))
root.mainloop()







