import sys
sys.stdout.reconfigure(encoding='utf-8')
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp('http://localhost:9222')
    context = browser.contexts[0]
    page = context.pages[0]
    
    url = 'https://www.facebook.com/profile.php?id=61594841053758'
    print('Navigating to root profile...')
    page.goto(url, wait_until='domcontentloaded', timeout=30000)
    page.wait_for_timeout(4000)
    
    page.screenshot(path=r'C:\Projects\Historical\FacebookAutoPoster\profile_overview_complete.png')
    print('Saved profile_overview_complete.png!')
    
    # Print the profile text
    main_el = page.locator("div[role='main']")
    if main_el.count() > 0:
        lines = [l.strip() for l in main_el.inner_text().split('\n') if l.strip()]
        print('=== PROFILE HEADER & INTRO ===')
        for line in lines[:40]:
            print(line)
