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

html = sys.stdin.read()
s = B(html, 'html.parser')

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

print('=== All direct children of m-dttexts ===')
for i, ch in enumerate(c.children):
    if ch.name:
        cls = ch.get('class')
        print(f'[{i}] <{ch.name}> class={cls}')
        txt = ch.get_text(strip=True)
        print(f'    text_preview={txt[:60]}')
        # Check for tables inside
        tbls = ch.find_all('table')
        if tbls:
            print(f'    INNER_TABLES: {len(tbls)}')
        imgs = ch.find_all('img')
        if imgs:
            print(f'    INNER_IMGS: {len(imgs)}')
    else:
        t = str(ch).strip()
        if t:
            print(f'[{i}] text_text={t[:60]}')

# Find title
h1 = s.find('h1')
print(f'\nh1 found: {h1 is not None}')
if h1:
    print(f'h1 text: {h1.text.strip()[:60]}')

# Check various title sources
for sel in ['h1', 'h2', 'h3', '.m-detailbox h1', '.m-pgpdbox1', '.article-title']:
    el = s.select_one(sel)
    if el:
        print(f'{sel}: {el.text.strip()[:60]}')
        break

print('\nFirst 800 chars of content HTML:')
print(str(c)[:800])
