"""
练习 01: 用 Playwright 打开一个网页。

目标:
1. 自己导入 `sync_playwright`
2. 启动一个可见的 Chromium 浏览器
3. 新建一个页面并打开 URL
4. 打印当前页面标题和 URL

建议:
- 第一版先不要封装太多函数
- 先把浏览器正常打开，再补打印信息
- 写完后记得主动关闭浏览器

运行:
    ./.venv/bin/python learning/playwright_basics/01_open_page.py
"""

DEFAULT_URL = "https://example.com/"


def main() -> None:
    from playwright.sync_api import sync_playwright

    with sync_playwright() as playwright:
        browser = playwright.chromium.launch(headless=False)
        page = browser.new_page()
        page.goto(DEFAULT_URL)
        print(f"[INFO] 已打开 URL: {page.url}")
        print(f"[INFO] 页面标题: {page.title()}")
        input("按回车退出...")
        browser.close()


if __name__ == "__main__":
    main()
