mcpField
B
browser-use

browser-use

github.com/kudosxAgent 工作流87 次安装
代码仓库

关于 browser-use

面向 Agent 的浏览器自动化技能,使用 Playwright 浏览网站并与网页交互。其脚本还支持下载图片、搜索视频以及保存登录会话。

主要功能

  1. 01基于 Playwright 浏览网页
  2. 02从网站下载图片
  3. 03YouTube 搜索与下载选项
  4. 04TikTok 视频搜索
  5. 05复用浏览器登录会话

适用场景

  1. 01自动浏览网站并与网页交互
  2. 02按查询条件查找并下载图片
  3. 03按时长或日期筛选视频搜索
  4. 04使用已保存会话浏览需登录的页面

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/kudosx/claude-skill-browser-use --skill browser-use

安装后在 Claude Code 中输入/browser-use确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

VERSION
references/playwright-python-docs/
actions.md
authentication.md
browsers.md
downloads.md
references/tips/
authentication-sessions.md
browser-automation.md
browser-manual.md
google-images-optimization.md
tiktok-optimization.md
web-scraping.md
youtube-optimization.md
scripts/
.python-version
browser.py
google_image.py
pyproject.toml
README.md
tiktok.py
uv.lock
youtube.py

详细介绍

Browser Use 技能

概述

此技能支持使用 Playwright 浏览网站并与网页交互。

快速开始 - 使用脚本

重要提示: 所有 uv run 命令都必须在 scripts 文件夹中执行(而非项目根目录):

cd .claude/skills/browser-use/scripts

# === MANUAL BROWSING (opens browser for user interaction) ===
# Open browser for manual use (waits for user to close)
uv run browser.py open https://example.com --wait 60
uv run browser.py open https://example.com --account myaccount --wait 120

# === AUTOMATION (headless, returns content) ===
# Navigate to a URL and get content
uv run browser.py auto https://example.com
uv run browser.py auto https://example.com --account myaccount

# Take a screenshot
uv run browser.py screenshot https://example.com -o screenshot.png

# Extract text from a page
uv run browser.py text https://example.com --selector "h1"

# Get all links from a page
uv run browser.py links https://example.com

# Save page as PDF
uv run browser.py pdf https://example.com -o page.pdf

# Download a file by clicking a download link
uv run browser.py download https://example.com/downloads "a.download-btn" -o ~/Downloads

# Upload file(s) to a page
uv run browser.py upload https://example.com/upload "input[type=file]" myfile.pdf
uv run browser.py upload https://example.com/upload "input[type=file]" file1.txt file2.txt --submit "button[type=submit]"

# Upload via file chooser dialog (for dynamic inputs)
uv run browser.py upload-chooser https://example.com/upload "button.upload-trigger" myfile.pdf

# Click an element
uv run browser.py click https://example.com "button.submit"

# Fill an input field and press Enter
uv run browser.py fill https://google.com "input[name=q]" "search term" --press Enter

# Extract attribute from elements
uv run browser.py extract https://example.com "img" --attr src --all

图片下载命令

以优化的性能从网站下载图片:

cd .claude/skills/browser-use/scripts

# Download images directly from src attribute
uv run browser.py download-images https://example.com "img.gallery" -n 10 -o ./images

# Download from Google Images (19x faster with regex extraction)
uv run browser.py download-from-gallery \
  "https://www.google.com/search?q=keyword&tbm=isch&tbs=isz:l" \
  "div[data-id] img" \
  "img[jsname='kn3ccd']" \
  -n 100 \
  -o ~/Downloads \
  -a myaccount

# Search Google Images with size filter
uv run browser.py google-image "landscape wallpaper" -n 50 -o ~/Downloads -s Large

# Download 4K images (3840px+ minimum)
uv run browser.py google-image "wallpaper" -n 20 -o ~/Downloads -s 4k

# Download FullHD images (1920px+ minimum)
uv run browser.py google-image "wallpaper" -n 50 -o ~/Downloads -s fullhd
Google 图片尺寸筛选

CLI 尺寸选项(按最小尺寸筛选):

  • -s 4k - 最小 3840px(4K 分辨率)
  • -s fullhd - 最小 1920px(全高清)
  • -s Large - 最小 1000px
  • -s Medium - 最小 400px
  • -s Icon - 无最小尺寸限制

Google URL 参数(内部使用):

  • tbs=isz:l - 大尺寸图片
  • tbs=isz:m - 中尺寸图片
  • tbs=isz:i - 图标尺寸

YouTube 命令

搜索并下载 YouTube 视频,可按时长和日期筛选:

cd .claude/skills/browser-use/scripts

# Search YouTube and get video URLs (returns JSON)
uv run browser.py youtube-search "python tutorial" -n 10
uv run browser.py youtube-search "lofi music" -n 5 -o results.json -s screenshot.png

# Search with duration filter (4-20 minutes)
uv run browser.py youtube-search "lofi music" -n 5 -min 4 -max 20

# Search videos from the last week
uv run browser.py youtube-search "news" -n 10 -t week

# Search with custom date range (YYYYMMDD format)
uv run browser.py youtube-search "tutorial" -n 10 -df 20240101 -dt 20241231

# Download a single video by URL
uv run browser.py youtube-download "https://www.youtube.com/watch?v=dQw4w9WgXcQ" -o ~/Downloads

# Download with quality options
uv run browser.py youtube-download "https://youtube.com/watch?v=..." -q 720p -o ~/Downloads
uv run browser.py youtube-download "https://youtube.com/watch?v=..." -q 1080p -o ~/Downloads

# Download audio only (mp3)
uv run browser.py youtube-download "https://youtube.com/watch?v=..." -a -o ./music

# Search and download in one command
uv run browser.py youtube-download "lofi hip hop" --search -o ~/Downloads
uv run browser.py youtube-download "python tutorial" --search -n 3 -o ~/Downloads

# Search and download with duration filter (4-20 min videos only)
uv run browser.py youtube-download "lofi music" --search -n 5 -min 4 -max 20 -o ~/Downloads

# Search and download videos from a date range
uv run browser.py youtube-download "tutorial" --search -n 5 -df 20240101 -dt 20241231 -o ~/Downloads
YouTube 时长筛选
  • -min N - 最短时长(分钟)
  • -max N - 最长时长(分钟)
  • 筛选使用 YouTube URL 参数以提高速度,并以 Python 端验证作为备用
YouTube 日期筛选
  • -t, --upload-date - 按上传日期筛选:hour、today、week、month、year
  • -df, --date-from - 自定义日期范围的开始日期(YYYYMMDD 格式,例如 20240101)
  • -dt, --date-to - 自定义日期范围的结束日期(YYYYMMDD 格式,例如 20241231)
YouTube 画质选项
  • best - 最佳可用画质(默认)
  • 1080p - 1080p 或更低
  • 720p - 720p 或更低
  • 480p - 480p 或更低
  • 360p - 360p 或更低
  • audio - 仅最佳音频
YouTube 搜索输出格式
[
  {
    "url": "https://www.youtube.com/watch?v=...",
    "title": "Video Title",
    "channel": "Channel Name",
    "duration": "10:30",
    "views": "1.2M views",
    "date": "2024-12-01"
  }
]

TikTok 命令

重要提示: TikTok 会拦截无头浏览器。搜索操作请使用 --no-headless。

cd .claude/skills/browser-use/scripts

# Login and save session for authenticated operations
uv run browser.py tiktok-login -a mytiktok
uv run browser.py tiktok-login -a mytiktok -w 180  # Extended wait for 2FA

# Search videos (--no-headless required for TikTok)
uv run browser.py tiktok-search "keyword" -n 10 --no-headless
uv run browser.py tiktok-search "#dance" -n 5 --no-headless  # By hashtag
uv run browser.py tiktok-search "cooking" -n 10 -a mytiktok --no-headless  # With account

# Download single video
uv run browser.py tiktok-download "https://tiktok.com/@user/video/123" -o ~/Downloads

# Search and download
uv run browser.py tiktok-download "funny cats" --search -n 5 -o ~/Downloads --no-headless
uv run browser.py tiktok-download "#cooking" --search -n 10 -o ~/Downloads -p 3 --no-headless
TikTok 搜索输出格式
[
  {
    "url": "https://www.tiktok.com/@user/video/123456789",
    "title": "Video description...",
    "author": "username",
    "views": "1.2M",
    "likes": "50K",
    "date": "2d ago"
  }
]

身份验证

保存并在不同浏览器命令之间重复使用登录会话。使用启用了隐身模式的 Chrome 绕过自动化检测(适用于 Google 等):

# Run from scripts folder
cd .claude/skills/browser-use/scripts

# Step 1: Create a login session (opens Chrome for manual login)
# Browser will open maximized - login manually then CLOSE THE BROWSER when done
uv run browser.py create-login https://gemini.google.com/app --account myaccount

# Options:
#   --wait, -w    Seconds to wait for login (default: 120)
#   --channel, -c Browser: chrome, msedge, chromium (default: chrome)

# Step 2: List saved accounts
uv run browser.py accounts

# Step 3: Use saved account with commands
# Manual browsing (opens browser for user interaction)
uv run browser.py open https://gemini.google.com/app --account myaccount

# Automation (headless, returns content)
uv run browser.py auto https://gemini.google.com/app --account myaccount
uv run browser.py screenshot https://gemini.google.com/app -o gemini.png --account myaccount
存储位置

身份验证信息存储在用户的主目录 ~/.auth/ 中:

~/.auth/
├── account-name.json          # Storage state (cookies, localStorage)
└── profiles/
    └── account-name/          # Persistent browser profile

此位置由所有项目共享,且不会提交到 git。

最佳实践
  • 自动化任务使用 headless=True
  • 调试或需要目视确认时使用 headless=False
  • 使用后务必关闭浏览器
  • 尽可能优先使用特定选择器(id、data-testid),而非通用选择器
  • 为动态内容添加适当的等待
  • 使用 try/except 块妥善处理超时
常用选择器
  • 按 ID:#element-id
  • 按类:.class-name
  • 按文本:text=Button Text
  • 按角色:role=button[name="Submit"]
  • 按 CSS:div.container > p.content
  • 按 XPath:xpath=//div[@class='item']

评论

支持 Markdown