#!/usr/bin/env python3
import sys, re, subprocess
from bs4 import BeautifulSoup

url = "http://www.taiqian.gov.cn/content/2026/1287192.html"
result = subprocess.run([
    "curl", "-sL", "--max-time", "15",
    "-H", "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
    "-H", "Accept: text/html",
    url
], capture_output=True, text=True, timeout=30)
soup = BeautifulSoup(result.stdout, "html.parser")

cd = soup.find("div", class_="show-content")
if cd:
    parts = []
    for el in cd.find_all(["p", "div", "table", "img"]):
        if el.name in ("p", "div") and not el.find_parent("table"):
            txt = el.get_text(" ", strip=True)
            txt = re.sub(r"\s+", " ", txt)
            txt = re.sub(r"(?<=[\u4e00-\u9fff])\s+(?=[\u4e00-\u9fff])", "", txt)
            if txt:
                parts.append(txt)
                print(f"  ADDED [{el.name}]: {txt[:60]}")
            else:
                print(f"  SKIP [{el.name}]: empty")
        elif el.name == "table":
            parts.append("[TABLE]")
        elif el.name == "img":
            parts.append("[IMG]")
    
    final = "\n\n".join(parts)
    print(f"\nFinal content: {len(final)} chars")
    print(f"Preview: {final[:200]}")
else:
    print("No show-content div found!")
