import asyncio, os, sys
sys.path.insert(0, r'D:\Workspace\claudeCode\AutonetSellCar.com\backend')
os.chdir(r'D:\Workspace\claudeCode\AutonetSellCar.com\backend')
from playwright.async_api import async_playwright

async def analyze():
    url = "https://ck.carmodoo.com/carCheck/carmodooPrint.do?print=0&checkNum=7400044430"

    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=True)
        page = await browser.new_page(viewport={'width': 1400, 'height': 900})
        await page.goto(url, wait_until='networkidle', timeout=60000)
        await page.wait_for_timeout(3000)

        # Get page structure
        result = await page.evaluate("""() => {
            const body = document.body;
            const children = Array.from(body.children);

            // Find elements that look like pages
            const pageSelectors = ['.page', '[class*="page"]', 'table', '.print', '[class*="print"]'];
            const found = {};

            pageSelectors.forEach(sel => {
                const elems = document.querySelectorAll(sel);
                if (elems.length > 0) {
                    found[sel] = {
                        count: elems.length,
                        firstClass: elems[0].className,
                        firstTag: elems[0].tagName
                    };
                }
            });

            // Get direct children of body
            const bodyChildren = children.map(c => ({
                tag: c.tagName,
                class: c.className,
                id: c.id,
                height: c.offsetHeight
            }));

            return { found, bodyChildren: bodyChildren.slice(0, 20) };
        }""")

        print("=== Found elements ===")
        for sel, info in result['found'].items():
            print(f"  {sel}: {info}")

        print("\n=== Body children ===")
        for child in result['bodyChildren']:
            print(f"  {child['tag']} class='{child['class']}' id='{child['id']}' height={child['height']}")

        await browser.close()

asyncio.run(analyze())
