基本完成

This commit is contained in:
2026-08-25 23:30:05 +08:00
parent 20936d109f
commit 243359b1af
8 changed files with 434 additions and 27 deletions
+20 -8
View File
@@ -7,6 +7,7 @@ Boss直聘 低痕迹 CDP 客户端
- 读 DOM:CDP WebSocket 的 Runtime.evaluate(一次性表达式求值)
"""
import json
import random
import time
from html.parser import HTMLParser
@@ -97,6 +98,25 @@ class CDPSession:
"type": "mouseReleased", "x": int(x), "y": int(y),
"button": "left", "clickCount": 1})
def human_click(self, x: float, y: float) -> None:
"""拟人化可信点击:先从上次位置移动鼠标(带轨迹),
再以随机偏移落下,避免“无 mousemove 历史 + 永远点正中心”的机器特征"""
tx = x + random.uniform(-6, 6)
ty = y + random.uniform(-4, 4)
sx, sy = getattr(self, "_last_xy", (
tx + random.uniform(-260, 260), ty + random.uniform(-180, 180)))
steps = random.randint(3, 6)
for i in range(1, steps + 1):
t = i / steps
self.call("Input.dispatchMouseEvent", {
"type": "mouseMoved",
"x": int(sx + (tx - sx) * t + random.uniform(-3, 3)),
"y": int(sy + (ty - sy) * t + random.uniform(-3, 3)),
"button": "none"})
time.sleep(random.uniform(0.02, 0.06))
self.click_at(tx, ty)
self._last_xy = (tx, ty)
def close(self) -> None:
try:
self.ws.close()
@@ -151,14 +171,6 @@ class LiteCDP:
except Exception:
pass
def activate_tab(self, tab_id: str) -> None:
"""重新激活指定标签页(开/关临时标签会夺走焦点,
后台标签上的可信鼠标点击会失效,需恢复前台)"""
try:
requests.get(f"{self._endpoint()}/json/activate/{tab_id}", timeout=5)
except Exception:
pass
def tab_url(self, tab_id: str) -> str | None:
for t in self.list_tabs():
if t.get("id") == tab_id: