跳到正文

拟人化输入

启用 humanize 后,SDK 会让鼠标移动、点击、滚动和打字遵循接近真人的轨迹与节奏。showCursor 会绘制指针,方便你观察。

拟人化输入(humanize & showCursor)

传入 humanize 后,所有输入——移动、点击、拖拽、滚动和打字——都遵循同一套拟人化标准,既覆盖页面级操作(page.click / hover / type / fill / mouse.* / keyboard.type),也覆盖 locator 级操作(locator.click / type / fill / pressSequentially / dragTo / …)。移动轨迹是一条从上一次光标位置出发、略带弧度的三次贝塞尔曲线,并按最小加加速度(min-jerk)子运动叠加的方式走完(一次弹道式主运动 + 一次修正运动——也就是真实伸手动作那种多峰的速度曲线,而不是单个对称的钟形曲线),所有操作都以真实、可信的事件派发(isTrusted === true,且 navigator.webdriver 保持为 false)。在 Pro 上,坐标点击(mouse.click(x, y))沿用从真人身上录制的运动轨迹;其他所有操作,以及开源版构建和 GitHub 免费版上的每一次点击,都使用生成的路径。加上 showCursor 会绘制一个跟随运动的圆点,方便你观察。

由于移动使用的是原生输入,用 mouse.down() 按下的鼠标按键会在整个移动过程中保持按住——因此 down → move → up 是一次真正按住按键的拖拽(滑块之类的拖动定位控件收到的是真实按下状态的拖拽),locator.dragTo 同样是拟人化的。打字逐键进行,按键间隔随机化,在词语边界处会停顿,偶尔还会打错再改正;滚动采用 ease-out 惯性,偶尔会有阅读停顿。fill 会先聚焦输入框再逐字输入(超过约 200 个字符的值仍一次性填入,免得批量填充慢如蜗牛)。

from clearcote import launch

browser = launch(fingerprint="seed-123", humanize=True, show_cursor=True)
page = browser.new_page()
page.goto("https://example.com")

page.click("text=Sign in")               # eased curve, then a trusted click
page.fill("#email", "you@example.com")   # focus + key-by-key human typing
page.locator("#password").type("s3cr3t") # locators are humanized too

# held-button drag (e.g. a slider): the press stays held across the move
x0, y0, x1 = 100, 300, 400               # the handle's start, and where to release it
page.mouse.move(x0, y0); page.mouse.down()
page.mouse.move(x1, y0); page.mouse.up()
browser.close()