ỨNG DỤNG NỘI THẤT THEO THÓI QUEN SỬ DỤNG I HƯỚNG CẢI TẠO MỚI CHO NHÀ Ở HIỆN ĐẠI

Ngày đăng: 15-07-2026
from pathlib import Path from bs4 import BeautifulSoup, NavigableString, Tag import re src = Path("/mnt/data/Văn bản đã dán (1)(53).txt") out = Path("/mnt/data/code-thi-cong-noi-that-theo-nhu-cau-hoan-chinh.html") raw = src.read_text(encoding="utf-8", errors="ignore") soup = BeautifulSoup(raw, "html.parser") heading_texts = { "Khảo Sát Theo Nhu Cầu Sử Dụng Thực Tế", "Tối Ưu Công Năng Cho Từng Không Gian", "Thi Công Theo Kích Thước Thực Tế", "Đồng Bộ Vật Liệu Và Màu Sắc", "Hoàn Thiện Và Bàn Giao Công Trình", "Liên Hệ Tư Vấn Thi Công Nội Thất", "SỬA NHÀ KON TUM", } p_style = ( "margin:0 15px 15px; " "font-family:'Times New Roman', Times, serif; " "font-size:16px; line-height:1.7; " "text-align:justify; color:#222;" ) h2_style = ( "margin:38px 15px 18px; " "color:#0b5fa5; " "font-family:'Times New Roman', Times, serif; " "font-size:22px; line-height:1.4; " "font-weight:700; text-align:center;" ) img_p_style = "margin:22px 20px; text-align:center;" img_style = ( "display:block; width:100%; max-width:100%; " "height:auto; margin:0 auto;" ) contact_p_style = ( "margin:4px 15px; " "font-family:'Times New Roman', Times, serif; " "font-size:16px; line-height:1.7; " "text-align:center; color:#222;" ) result = [] for node in soup.contents: if isinstance(node, NavigableString): continue if not isinstance(node, Tag): continue text = " ".join(node.get_text(" ", strip=True).split()) text = text.replace("????", "").strip() if not text and not node.find("img"): continue # Image-only paragraph img = node.find("img") if img and not text: src_url = img.get("src", "") alt = img.get("alt", "") result.append( f'

\n' f'{alt}\n' f'

' ) continue # Headings, including paragraphs that should be headings if node.name == "h2" or text in heading_texts: size = "20px" if text == "SỬA NHÀ KON TUM" else "22px" extra_margin = "40px 15px 12px" if text == "SỬA NHÀ KON TUM" else "38px 15px 18px" result.append( f'

\n' f'{text}\n

' ) continue # Contact lines if any(label in text for label in ["Địa chỉ:", "Hotline:", "Website:", "Email:"]): # Preserve mailto link where available clean_html = str(node) clean_html = re.sub(r"]*>", "", clean_html) clean_html = clean_html.replace("", "") clean_html = re.sub(r"^\s*]*>", "", clean_html) clean_html = re.sub(r"

\s*$", "", clean_html) clean_html = clean_html.replace("????", "").replace("✉️", "").strip() result.append(f'

\n{clean_html}\n

') continue # Standard paragraph, preserving strong tags and links clean_html = str(node) clean_html = re.sub(r"]*>", "", clean_html) clean_html = clean_html.replace("", "") clean_html = re.sub(r"^\s*]*>", "", clean_html) clean_html = re.sub(r"

\s*$", "", clean_html) clean_html = clean_html.replace("????", "").strip() # Center the service promise sentence if "Khảo sát miễn phí" in text: result.append( f'

\n' f'{clean_html}\n

' ) else: result.append(f'

\n{clean_html}\n

') html = "\n\n".join(result).strip() + "\n" out.write_text(html, encoding="utf-8") print(out)

Hoạt động khác