#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 测试 Playwright 基本功能 """ import asyncio from playwright.async_api import async_playwright async def test_playwright(): """测试 Playwright""" print("开始测试 Playwright...") playwright = await async_playwright().start() print("Playwright 启动成功") browser = await playwright.chromium.launch( headless=True, args=['--no-sandbox', '--disable-setuid-sandbox'] ) print("浏览器启动成功") page = await browser.new_page() print("页面创建成功") await page.goto('https://www.baidu.com', timeout=30000) print("页面加载成功") title = await page.title() print(f"页面标题: {title}") await browser.close() await playwright.stop() print("测试完成") if __name__ == '__main__': asyncio.run(test_playwright())