🛡️ Camofox 是 OpenClaw 内置的反检测浏览器。基于 Firefox 魔改,专门用于绕过网站的反爬虫检测。本文教你如何使用 Camofox 实现高级网页自动化。
随机化浏览器指纹,包括 Canvas、WebGL、AudioContext 等
支持代理池自动轮换,避免 IP 封禁
模拟真实用户的鼠标移动、点击、滚动行为
模拟不同设备和浏览器环境
# 创建 Camofox 标签页
camofox_create_tab(url="https://example.com")
# 返回 tabId,后续操作需要使用
# tabId: "tab_123456"
# 获取页面元素快照
camofox_snapshot(tabId="tab_123456")
# 返回元素引用列表
# e1: button "登录"
# e2: input "用户名"
# e3: input "密码"
# 点击元素
camofox_click(tabId="tab_123456", ref="e1")
# 输入文本
camofox_type(tabId="tab_123456", ref="e2", text="my_username")
# 滚动页面
camofox_scroll(tabId="tab_123456", direction="down", amount=500)
# 截图
camofox_screenshot(tabId="tab_123456")
# 导航到新页面
camofox_navigate(tabId="tab_123456", url="https://example.com/page2")
# 等待特定元素出现
# 使用 snapshot 检查元素是否加载完成
# 在页面上下文执行 JS
camofox_evaluate(
tabId="tab_123456",
expression="document.title"
)
# 获取页面数据
camofox_evaluate(
tabId="tab_123456",
expression="JSON.stringify(window.__DATA__)"
)
# 导入已有 Cookie
camofox_import_cookies(
cookiesPath="/path/to/cookies.txt",
domainSuffix=".example.com"
)
# 完整的自动化登录流程
# 1. 创建标签页
tab = camofox_create_tab(url="https://example.com/login")
# 2. 等待页面加载
camofox_snapshot(tabId=tab)
# 3. 输入用户名
camofox_type(tabId=tab, ref="e2", text="my_username")
# 4. 输入密码
camofox_type(tabId=tab, ref="e3", text="my_password")
# 5. 点击登录按钮
camofox_click(tabId=tab, ref="e1")
# 6. 验证登录成功
camofox_snapshot(tabId=tab)
# 检查是否出现用户头像等元素
# 在操作间添加随机延迟
import random
import time
def human_delay():
time.sleep(random.uniform(0.5, 2.0))
camofox_click(tabId=tab, ref="e1")
human_delay()
camofox_type(tabId=tab, ref="e2", text="input")
human_delay()
尝试:更换代理、清除指纹、降低请求频率、使用不同的 User-Agent。
可以集成第三方验证码识别服务,或使用人工介入模式。
支持大部分网站,但某些高级反爬系统可能仍需特殊处理。