# 使用 Python 实现浏览器自动化提交表单

下面示例使用 Playwright（同步 API）自动完成登录、进入测评、并连续点击选项 90 次。

## 环境准备
```bash
python -m pip install playwright
playwright install
```

## 示例脚本
```python
from playwright.sync_api import sync_playwright

URL = "https://psy5mp.xinliyun.cn/"
ID_CARD = "410323200512060159"
PASSWORD = "000000"

LOGIN_ID_INPUT = "#van-field-1-input"
LOGIN_PWD_INPUT = "#van-field-2-input"
LOGIN_BTN = "#app > div > form > div.form-act > button"

PAPER_ENTRY = "#app > div > div.layout-content > div.van-cell.van-cell--center.van-cell--clickable > div"
PAPER_START = "#app > div > div.paper-desc > div.paper-act.van-safe-area-bottom > button"

FIRST_OPTION = "#app > div > div.paper-quiz-wrapper > div.paper-detail > div.van-radio-group > div > div:nth-child(1)"

with sync_playwright() as p:
    browser = p.chromium.launch(headless=False)
    page = browser.new_page()

    page.goto(URL, wait_until="domcontentloaded")

    # 登录
    page.fill(LOGIN_ID_INPUT, ID_CARD)
    page.fill(LOGIN_PWD_INPUT, PASSWORD)
    page.click(LOGIN_BTN)

    # 进入待测量表列表
    page.wait_for_selector(PAPER_ENTRY)
    page.click(PAPER_ENTRY)

    # 进入测评介绍页并开始
    page.wait_for_selector(PAPER_START)
    page.click(PAPER_START)

    # 连续选择第一个选项 90 次
    for _ in range(90):
        page.wait_for_selector(FIRST_OPTION)
        page.click(FIRST_OPTION)

    page.wait_for_timeout(1000)
    browser.close()
```

## 备注
- 如果页面切换很慢，可在关键步骤之间增加 `page.wait_for_timeout(500)`。
- 如果元素选择器变动，优先在浏览器开发者工具中更新选择器。
- 如需无头模式，将 `headless=False` 改为 `True`。
