skills/playwright_browser/SKILL.md
基于Playwright的高级浏览器自动化技能。支持动态网页抓取、点击/输入模拟、百度搜索、页面快照、数据提取和批量图片下载。当需要处理JavaScript渲染的页面、模拟用户交互或自动化网页操作时使用此技能。
npx skillsauth add arcaneorion/alice-single playwright_browserInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
此技能提供基于 Playwright 的完整浏览器自动化能力,支持在无头模式下执行复杂的网页交互任务。
访问网页、截图、读取 HTML 内容。
使用 CSS 选择器精确提取网页数据。
使用百度搜索引擎并返回结构化结果。
执行复杂的操作链,模拟真实用户行为。
高质量页面截图和 PDF 导出。
自动提取并下载网页中的所有图片。
访问网页并截图: ```bash python skills/playwright_browser/browser_tool.py --url https://example.com --screenshot --output example.png ```
读取页面 HTML 内容: ```bash python skills/playwright_browser/browser_tool.py --url https://example.com --read ```
等待特定元素加载: ```bash python skills/playwright_browser/browser_tool.py --url https://example.com --screenshot --wait .main-content ```
提取单个元素文本: ```bash python skills/playwright_browser/scraper.py https://example.com --selector title:h1:text ```
提取多个元素(如所有链接): ```bash python skills/playwright_browser/scraper.py https://example.com --selector links:a:href:multiple --json ```
提取特定属性: ```bash python skills/playwright_browser/scraper.py https://example.com --selector img_url:img:src ```
搜索关键词: ```bash python skills/playwright_browser/search.py "搜索关键词" --max 10 ```
JSON 格式输出: ```bash python skills/playwright_browser/search.py "搜索关键词" --json > results.json ```
使用 JSON 配置文件: ```bash python skills/playwright_browser/automator.py https://example.com --file actions.json ```
直接传入操作链: ```bash python skills/playwright_browser/automator.py https://example.com --actions '[{"type":"fill","selector":"#input","value":"test"},{"type":"click","selector":"#submit"}]' ```
actions.json 示例: ```json [ {"type": "wait", "delay": 2000}, {"type": "fill", "selector": "#username", "value": "alice"}, {"type": "fill", "selector": "#password", "value": "password"}, {"type": "click", "selector": "#login"}, {"type": "wait_for", "selector": ".dashboard"}, {"type": "screenshot", "filename": "dashboard.png"} ] ```
全页截图: ```bash python skills/playwright_browser/snapshot.py https://example.com --output fullpage --full-page ```
导出为 PDF: ```bash python skills/playwright_browser/snapshot.py https://example.com --output report --format pdf ```
下载网页中的所有图片: ```bash python skills/playwright_browser/download_images.py https://example.com --output-dir downloaded_images --max 10 ```
参数说明:
--output-dir: 输出目录(宿主机侧映射到 .alice/workspace/,容器内仍使用 alice_output/),默认为 "images"--max: 最大下载数量,默认为 20示例: ```bash
python skills/playwright_browser/download_images.py https://www.nvidia.cn --output-dir nvidia_images --max 5 ```
--no-sandbox 和 --disable-setuid-sandbox 参数.alice/workspace/,容器内兼容路径仍为 alice_output/| 类型 | 参数 | 说明 |
|------|------|------|
| click | selector | 点击指定元素 |
| fill | selector, value | 输入文本 |
| select | selector, value | 下拉选择 |
| wait | delay | 等待指定毫秒数 |
| scroll | selector 或 position | 滚动到元素或页面顶部/底部 |
| screenshot | filename | 保存截图 |
| evaluate | script | 执行 JavaScript |
| wait_for | selector | 等待元素出现 |
选择器参数格式:name:css_selector:attribute[:multiple]
name: 提取结果的键名css_selector: CSS 选择器attribute: 要提取的属性,默认 text(文本内容)multiple: 可选,设为 true 时提取所有匹配项示例:
title:h1:text - 提取 h1 标签的文本images:img:src:multiple - 提取所有 img 的 src 属性links:a:href - 提取第一个 a 标签的 href--no-sandbox 参数(已自动处理)--wait 参数或 wait_for 操作playwright 包及浏览器二进制文件```bash pip install playwright playwright install chromium ```
Q: 如何处理需要登录的页面? A: 使用 automator.py 的操作链,按顺序执行 fill (用户名) → fill (密码) → click (登录按钮) → wait_for (登录后元素)
Q: 如何提取 JavaScript 动态生成的内容?
A: 使用 browser_tool.py 的 --wait 参数或 scraper.py 的 --wait 参数等待元素加载
Q: 如何处理弹出框?
A: 使用 automator.py 的 evaluate 操作执行 JavaScript 关闭,或在页面上下文中提前禁用
Q: 为什么某些网站无法访问? A: 可能是反爬虫限制,可以尝试设置 user-agent 或使用代理(需修改代码添加 context 配置)
Q: 为什么只下载了部分图片? A: 某些图片可能有加载延迟、防盗链或 base64 编码。脚本会自动跳过无法访问的图片
Q: 下载的图片文件名如何确定? A: 脚本会优先使用 img 标签的 alt 属性,其次是 title 属性。如果没有则使用 "image_N" 格式
tools
Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.
development
Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas
tools
获取微博热搜榜实时数据。当需要查看微博热点、热门话题、实时舆情时使用该技能。
development
直接从专业天气API获取实时天气数据和历史天气信息。当需要查询任意城市的当前天气、未来预报、空气质量等精准气象数据时使用该技能。