#!/usr/bin/env python3
import requests
from bs4 import BeautifulSoup

url = "https://www.jinjiang.gov.cn/ztzl/lhzt/lyxx/sthj/202606/t20260618_3301831.htm"
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}
r = requests.get(url, timeout=30, headers=headers)
print("Status:", r.status_code, "Len:", len(r.text))

soup = BeautifulSoup(r.text, "html.parser")

# Check TRS_Editor
trs = soup.select_one(".TRS_Editor")
if trs:
    print("Found TRS_Editor:", len(str(trs)))
    tables = trs.find_all("table")
    print("Tables in TRS_Editor:", len(tables))

# Check article_area
area = soup.select_one(".article_area")
if area:
    print("Found article_area:", len(str(area)))
    tables = area.find_all("table")
    print("Tables in article_area:", len(tables))

# Check other content selectors
for c in ["content", "zoom", "detail", "main", "article", "font", "g-content"]:
    div = soup.select_one("." + c)
    if div:
        tags = div.find_all(["table", "p", "div"])
        tag_str = ", ".join([f"{t.name}" for t in tags[:10]])
        print("Found .{}: {} chars, tags: {}".format(c, len(str(div)), tag_str))

# Show article_area structure
if area:
    print("\n=== article_area structure ===")
    for child in area.children:
        if hasattr(child, "name"):
            cls = child.get("class", "")
            print("  <{}> class={} text={}".format(
                child.name, cls, child.get_text()[:60]
            ))
else:
    # Try finding the actual content
    print("\n=== Searching for content area ===")
    for tag in soup.find_all(["div", "article"]):
        cls = str(tag.get("class", ""))
        tid = str(tag.get("id", ""))
        txt = tag.get_text(strip=True)[:80]
        if any(x in cls.lower() + tid.lower() for x in ["content", "article", "detail", "main", "text", "zoom", "font"]):
            print("  <{}> class={} id={} text={}".format(tag.name, cls, tid, txt))

# Also dump tables
print("\n=== Tables on page ===")
for t in soup.find_all("table"):
    print("TABLE:", str(t)[:300])
