#!/usr/bin/env python3
"""Debug ningguo detail page structure"""
from bs4 import BeautifulSoup as B
import sys, re

html = sys.stdin.read()
s = B(html, 'html.parser')
t = s.find('h1')
print('TITLE:', t.text.strip() if t else 'N/A')

c = s.find('div', class_='m-dttexts')
if not c:
    print('NO CONTENT')
    sys.exit(1)

print('HTML length:', len(str(c)))
print()
print('=== CHILDREN ===')
for i, ch in enumerate(c.children):
    if ch.name:
        cls = ch.get('class')
        print(f'[{i}] <{ch.name}> class={cls}')
        if ch.name == 'table':
            rows = ch.find_all('tr')
            print(f'    TABLE: {len(rows)} rows')
            for tr in rows[:3]:
                cells = [td.get_text(strip=True) for td in tr.find_all(['td','th'])]
                print(f'      | {" | ".join(cells)} |')
        elif ch.name == 'p':
            txt = ch.get_text(strip=True)
            has_img = ch.find('img') is not None
            has_table = ch.find('table') is not None
            if has_img:
                print(f'    P(img) text={txt[:60]}')
            elif has_table:
                print(f'    P(table) text={txt[:60]}')
            else:
                print(f'    P text={txt[:80]}')
        elif ch.name in ('div','span'):
            txt = ch.get_text(strip=True)
            if txt:
                print(f'    text={txt[:80]}')
        elif ch.name == 'img':
            src = ch.get('src','')
            print(f'    IMG src={src}')
    else:
        t = str(ch).strip()
        if t:
            print(f'[{i}] text={t[:50]}')

# Show tables HTML for debugging
tables = c.find_all('table')
print(f'\n=== TABLES ({len(tables)}) ===')
for ti, tbl in enumerate(tables):
    print(f'--- Table {ti+1} ---')
    print(str(tbl)[:400])
