from pathlib import Path import zipfile, os, shutil, re, textwrap src = Path("/mnt/data/taiwan_stock_line_landing_page_upgraded.zip") work = Path("/mnt/data/tw_v2_work") out = Path("/mnt/data/taiwan_stock_line_landing_page_v2.zip") if work.exists(): shutil.rmtree(work) work.mkdir() with zipfile.ZipFile(src, "r") as z: z.extractall(work) # Find html entry html_files = list(work.rglob("*.html")) if html_files: html = html_files[0] content = html.read_text(encoding="utf-8", errors="ignore") # Add v2 enhancement styles/content before closing body addon = r"""

每日掌握台股市場機會

專業整理市場趨勢、熱門產業與投資觀察,讓您快速掌握市場資訊。

市場趨勢

追蹤台股熱門方向

產業分析

掌握熱門產業變化

即時資訊

手機快速查看更新

免費加入 LINE """ if "" in content: content = content.replace("", addon + "\n") else: content += addon html.write_text(content, encoding="utf-8") if out.exists(): out.unlink() with zipfile.ZipFile(out, "w", zipfile.ZIP_DEFLATED) as z: for p in work.rglob("*"): if p.is_file(): z.write(p, p.relative_to(work)) str(out)