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] if context.pages else context.new_page()
    
    # 1. Directory Work
    url_work = 'https://www.facebook.com/profile.php?id=61594841053758&sk=directory_work'
    print('Navigating to directory_work...')
    page.goto(url_work, wait_until='domcontentloaded', timeout=30000)
    page.wait_for_timeout(3000)
    page.screenshot(path=r'C:\Projects\Historical\FacebookAutoPoster\view_work.png')
    print('WORK TEXT:')
    print(page.locator("div[role='main']").inner_text()[:600])

    # 2. Directory Education
    url_edu = 'https://www.facebook.com/profile.php?id=61594841053758&sk=directory_education'
    print('\nNavigating to directory_education...')
    page.goto(url_edu, wait_until='domcontentloaded', timeout=30000)
    page.wait_for_timeout(3000)
    page.screenshot(path=r'C:\Projects\Historical\FacebookAutoPoster\view_edu.png')
    print('EDUCATION TEXT:')
    print(page.locator("div[role='main']").inner_text()[:600])
