基本完成

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
+46 -13
View File
@@ -116,6 +116,9 @@ _STAY_JS = """(() => {
return JSON.stringify({x: r.x + r.width / 2, y: r.y + r.height / 2});
})()"""
# 站点在沟通频控/处理中时会盖一层遮罩,此时点击无效,需等它消失后重试
_BLOCK_JS = "!!document.querySelector('.chat-block-layer')"
def _parse_salary(text: str) -> tuple[int, int] | None:
"""'20-30K·15薪' → (20, 30);'3K以下' → (0, 3);'50K以上' → (50, 999)"""
@@ -273,7 +276,7 @@ class Applicant:
f"({city_name or '未配置城市名'}),"
f"现有期望:{info.get('list') or '无'}")
return False
self._sess.click_at(info["x"], info["y"])
self._sess.human_click(info["x"], info["y"])
logger.info(f"已选中期望条件:{info.get('text')}")
time.sleep(2)
# 点击后站点自发请求第一页列表,被动监听捕获明文薪资
@@ -327,6 +330,15 @@ class Applicant:
))
return cards
def _human_scroll(self) -> None:
"""拟人分段滚动:多次随机步长 + 随机间隔,模拟真人拖滚轮,
避免一次性 scrollTo 到底的机器特征"""
for _ in range(random.randint(3, 5)):
step = random.randint(280, 560)
self._sess.eval_js(f"window.scrollBy(0, {step})")
time.sleep(random.uniform(0.3, 0.8))
self._sess.eval_js("window.scrollTo(0, document.body.scrollHeight)")
def _process_list(self, keyword, salary_min, salary_max,
min_score, delay_range, max_per_keyword: int = 15):
processed: set[str] = set()
@@ -348,8 +360,8 @@ class Applicant:
processed.add(card.job_id)
applied += self._handle_card(card, salary_min, salary_max,
min_score, delay_range)
# 下拉加载下一页:滚动到底,站点自发请求,被动监听
self._sess.eval_js("window.scrollTo(0, document.body.scrollHeight)")
# 下拉加载下一页:拟人分段滚动,站点自发请求,被动监听
self._human_scroll()
self._pump_list_responses(3)
self._sleep(1, 3)
@@ -438,27 +450,48 @@ class Applicant:
logger.warning(f"未能在列表中选中卡片:{card.title}")
return False
p = json.loads(pos)
self._sess.click_at(p["x"], p["y"])
self._sess.human_click(p["x"], p["y"])
time.sleep(1.5)
# 2. 可信点击"立即沟通"
xy = self._sess.eval_js(_btn_xy_js(".op-btn-chat"))
# 2. 等右侧面板加载,拟人点击"立即沟通"(面板渲染可能滞后,重试)
xy = None
for _ in range(5):
xy = self._sess.eval_js(_btn_xy_js(".op-btn-chat"))
if xy:
break
time.sleep(1)
if not xy:
logger.warning(f"右侧面板无立即沟通按钮:{card.title}")
return False
p = json.loads(xy)
self._sess.click_at(p["x"], p["y"])
self._sess.human_click(p["x"], p["y"])
# 3. 等待"已向BOSS发送消息"弹窗,点"留在此页"
for _ in range(10):
stay = self._wait_stay(10)
if not stay and self._sess.eval_js(_BLOCK_JS):
# 遮罩拦住了本次点击:等遮罩消失后重点一次
logger.info(f"沟通遮罩拦截,等待消失后重试:{card.title}")
for _ in range(10):
time.sleep(1)
if not self._sess.eval_js(_BLOCK_JS):
break
self._sess.human_click(p["x"], p["y"])
stay = self._wait_stay(10)
if stay:
q = json.loads(stay)
self._sess.human_click(q["x"], q["y"])
return True
logger.warning(f"点击立即沟通后未等到发送消息弹窗:{card.title}")
return False
def _wait_stay(self, timeout: float = 10):
"""轮询等待"留在此页"按钮出现,返回坐标 JSON 或 None"""
for _ in range(int(timeout)):
time.sleep(1)
stay = self._sess.eval_js(_STAY_JS)
if stay:
q = json.loads(stay)
self._sess.click_at(q["x"], q["y"])
return True
logger.warning(f"点击立即沟通后未等到发送消息弹窗:{card.title}")
return False
return stay
return None
# ------------------------------------------------------------------
# 服务端上报
+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: