跳到正文
Skillpedia
网页抓取29k · #9577

browser-automation

它能做什么

它为智能体提供使用 Playwright 控制浏览器的工具和模式,用于收集数据或完成重复的网页任务。适合自动化网络调研、数据收集或表单工作的人。

适用场景

  • ✓当你想从网站收集数据,例如表格或搜索结果时。
  • ✓当你需要完成多步骤的网页任务,例如填写表单或下载文件时。
  • ✓当你希望自动截取网页的屏幕截图或 PDF 时。

技能链接

https://github.com/alirezarezvani/claude-skills/blob/main/engineering/skills/browser-automation/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/alirezarezvani/claude-skills/blob/main/engineering/skills/browser-automation/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请把这个商店列表页面上的产品名称和价格收集到一份电子表格中。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体使用 Playwright 驱动浏览器,等待页面加载,提取内容并保存结果。辅助脚本会构建抓取器和表单流程。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Browser Automation - POWERFUL

Overview

The Browser Automation skill provides comprehensive tools and knowledge for building production-grade web automation workflows using Playwright. This skill covers data extraction, form filling, screenshot capture, session management, and anti-detection patterns for reliable browser automation at scale.

When to use this skill:

  • Scraping structured data from websites (tables, listings, search results)
  • Automating multi-step browser workflows (login, fill forms, download files)
  • Capturing screenshots or PDFs of web pages
  • Extracting data from SPAs and JavaScript-heavy sites
  • Building repeatable browser-based data pipelines

When NOT to use this skill:

  • Writing browser tests or E2E test suites — use playwright-pro instead
  • Testing API endpoints — use api-test-suite-builder instead
  • Load testing or performance benchmarking — use performance-profiler instead

Why Playwright over Selenium or Puppeteer:

  • Auto-wait built in — no explicit sleep() or waitForElement() needed for most actions
  • Multi-browser from one API — Chromium, Firefox, WebKit with zero config changes
  • Network interception — block ads, mock responses, capture API calls natively
  • Browser contexts — isolated sessions without spinning up new browser instances
  • Codegen — playwright codegen records your actions and generates scripts
  • Async-first — Python async/await for high-throughput scraping

Core Competencies

1. Web Scraping Patterns

Selector priority (most to least reliable):

  1. data-testid, data-id, or custom data attributes — stable across redesigns
  2. #id selectors — unique but may change between deploys
  3. Semantic selectors: article, nav, main, section — resilient to CSS changes
  4. Class-based: .product-card, .price — brittle if classes are generated (e.g., CSS modules)
  5. Positional: nth-child(), nth-of-type() — last resort, breaks on layout changes

Use XPath only when CSS cannot express the relationship (e.g., ancestor traversal, text-based selection).

Pagination strategies: next-button, URL-based (?page=N), infinite scroll, load-more button. See data_extraction_recipes.md for complete pagination handlers and scroll patterns.

2. Form Filling & Multi-Step Workflows

Break multi-step forms into discrete functions per step. Each function fills fields, clicks "Next"/"Continue", and waits for the next step to load (URL change or DOM element).

Key patterns: login flows, multi-page forms, file uploads (including drag-and-drop zones), native and custom dropdown handling. See playwright_browser_api.md for complete API reference on fill(), select_option(), set_input_files(), and expect_file_chooser().

3. Screenshot & PDF Capture

  • Full page: await page.screenshot(path="full.png", full_page=True)
  • Element: await page.locator("div.chart").screenshot(path="chart.png")
  • PDF (Chromium only): await page.pdf(path="out.pdf", format="A4", print_background=True)
  • Visual regression: Take screenshots at known states, store baselines in version control with naming: {page}_{viewport}_{state}.png

See playwright_browser_api.md for full screenshot/PDF options.

4. Structured Data Extraction

Core extraction patterns:

  • Tables to JSON — Extract <thead> headers and <tbody> rows into dictionaries
  • Listings to arrays — Map repeating card elements using a field-selector map (supports ::attr() for attributes)
  • Nested/threaded data — Recursive extraction for comments with replies, category trees

See data_extraction_recipes.md for complete extraction functions, price parsing, data cleaning utilities, and output format helpers (JSON, CSV, JSONL).

5. Cookie & Session Management

  • Save/restore cookies: context.cookies() and context.add_cookies()
  • Full storage state (cookies + localStorage): context.storage_state(path="state.json") to save, browser.new_context(storage_state="state.json") to restore

Best practice: Save state after login, reuse across scraping sessions. Check session validity before starting a long job — make a lightweight request to a protected page and verify you are not redirected to login. See playwright_browser_api.md

常见问题

它是用来测试网站的吗?

不是。浏览器测试由另一个技能 playwright-pro 负责。

它能处理依赖 JavaScript 的网站吗?

能。它涵盖从使用 JavaScript 加载内容的单页应用中提取数据。

它能在多种浏览器上运行吗?

能。Playwright 通过同一个接口支持 Chromium、Firefox 和 WebKit。

详情

作者的原始描述

Use for browser automation, scraping, form filling or structured extraction from web pages. Builds scrapers with scraping_toolkit.py and form flows with form_automation_builder.py. Browser testing: playwright-pro.

repo: alirezarezvani/claude-skills

热度

GitHub 星标
29k
排名
#9577
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能