基本完成
This commit is contained in:
@@ -116,6 +116,9 @@ _STAY_JS = """(() => {
|
|||||||
return JSON.stringify({x: r.x + r.width / 2, y: r.y + r.height / 2});
|
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:
|
def _parse_salary(text: str) -> tuple[int, int] | None:
|
||||||
"""'20-30K·15薪' → (20, 30);'3K以下' → (0, 3);'50K以上' → (50, 999)"""
|
"""'20-30K·15薪' → (20, 30);'3K以下' → (0, 3);'50K以上' → (50, 999)"""
|
||||||
@@ -273,7 +276,7 @@ class Applicant:
|
|||||||
f"({city_name or '未配置城市名'}),"
|
f"({city_name or '未配置城市名'}),"
|
||||||
f"现有期望:{info.get('list') or '无'}")
|
f"现有期望:{info.get('list') or '无'}")
|
||||||
return False
|
return False
|
||||||
self._sess.click_at(info["x"], info["y"])
|
self._sess.human_click(info["x"], info["y"])
|
||||||
logger.info(f"已选中期望条件:{info.get('text')}")
|
logger.info(f"已选中期望条件:{info.get('text')}")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
# 点击后站点自发请求第一页列表,被动监听捕获明文薪资
|
# 点击后站点自发请求第一页列表,被动监听捕获明文薪资
|
||||||
@@ -327,6 +330,15 @@ class Applicant:
|
|||||||
))
|
))
|
||||||
return cards
|
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,
|
def _process_list(self, keyword, salary_min, salary_max,
|
||||||
min_score, delay_range, max_per_keyword: int = 15):
|
min_score, delay_range, max_per_keyword: int = 15):
|
||||||
processed: set[str] = set()
|
processed: set[str] = set()
|
||||||
@@ -348,8 +360,8 @@ class Applicant:
|
|||||||
processed.add(card.job_id)
|
processed.add(card.job_id)
|
||||||
applied += self._handle_card(card, salary_min, salary_max,
|
applied += self._handle_card(card, salary_min, salary_max,
|
||||||
min_score, delay_range)
|
min_score, delay_range)
|
||||||
# 下拉加载下一页:滚动到底,站点自发请求,被动监听
|
# 下拉加载下一页:拟人分段滚动,站点自发请求,被动监听
|
||||||
self._sess.eval_js("window.scrollTo(0, document.body.scrollHeight)")
|
self._human_scroll()
|
||||||
self._pump_list_responses(3)
|
self._pump_list_responses(3)
|
||||||
self._sleep(1, 3)
|
self._sleep(1, 3)
|
||||||
|
|
||||||
@@ -438,28 +450,49 @@ class Applicant:
|
|||||||
logger.warning(f"未能在列表中选中卡片:{card.title}")
|
logger.warning(f"未能在列表中选中卡片:{card.title}")
|
||||||
return False
|
return False
|
||||||
p = json.loads(pos)
|
p = json.loads(pos)
|
||||||
self._sess.click_at(p["x"], p["y"])
|
self._sess.human_click(p["x"], p["y"])
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
|
|
||||||
# 2. 可信点击"立即沟通"
|
# 2. 等右侧面板加载,拟人点击"立即沟通"(面板渲染可能滞后,重试)
|
||||||
|
xy = None
|
||||||
|
for _ in range(5):
|
||||||
xy = self._sess.eval_js(_btn_xy_js(".op-btn-chat"))
|
xy = self._sess.eval_js(_btn_xy_js(".op-btn-chat"))
|
||||||
|
if xy:
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
if not xy:
|
if not xy:
|
||||||
logger.warning(f"右侧面板无立即沟通按钮:{card.title}")
|
logger.warning(f"右侧面板无立即沟通按钮:{card.title}")
|
||||||
return False
|
return False
|
||||||
p = json.loads(xy)
|
p = json.loads(xy)
|
||||||
self._sess.click_at(p["x"], p["y"])
|
self._sess.human_click(p["x"], p["y"])
|
||||||
|
|
||||||
# 3. 等待"已向BOSS发送消息"弹窗,点"留在此页"
|
# 3. 等待"已向BOSS发送消息"弹窗,点"留在此页"
|
||||||
|
stay = self._wait_stay(10)
|
||||||
|
if not stay and self._sess.eval_js(_BLOCK_JS):
|
||||||
|
# 遮罩拦住了本次点击:等遮罩消失后重点一次
|
||||||
|
logger.info(f"沟通遮罩拦截,等待消失后重试:{card.title}")
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
stay = self._sess.eval_js(_STAY_JS)
|
if not self._sess.eval_js(_BLOCK_JS):
|
||||||
|
break
|
||||||
|
self._sess.human_click(p["x"], p["y"])
|
||||||
|
stay = self._wait_stay(10)
|
||||||
if stay:
|
if stay:
|
||||||
q = json.loads(stay)
|
q = json.loads(stay)
|
||||||
self._sess.click_at(q["x"], q["y"])
|
self._sess.human_click(q["x"], q["y"])
|
||||||
return True
|
return True
|
||||||
logger.warning(f"点击立即沟通后未等到发送消息弹窗:{card.title}")
|
logger.warning(f"点击立即沟通后未等到发送消息弹窗:{card.title}")
|
||||||
return False
|
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:
|
||||||
|
return stay
|
||||||
|
return None
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 服务端上报
|
# 服务端上报
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ Boss直聘 低痕迹 CDP 客户端
|
|||||||
- 读 DOM:CDP WebSocket 的 Runtime.evaluate(一次性表达式求值)
|
- 读 DOM:CDP WebSocket 的 Runtime.evaluate(一次性表达式求值)
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
|
import random
|
||||||
import time
|
import time
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
|
||||||
@@ -97,6 +98,25 @@ class CDPSession:
|
|||||||
"type": "mouseReleased", "x": int(x), "y": int(y),
|
"type": "mouseReleased", "x": int(x), "y": int(y),
|
||||||
"button": "left", "clickCount": 1})
|
"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:
|
def close(self) -> None:
|
||||||
try:
|
try:
|
||||||
self.ws.close()
|
self.ws.close()
|
||||||
@@ -151,14 +171,6 @@ class LiteCDP:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
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:
|
def tab_url(self, tab_id: str) -> str | None:
|
||||||
for t in self.list_tabs():
|
for t in self.list_tabs():
|
||||||
if t.get("id") == tab_id:
|
if t.get("id") == tab_id:
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ def main():
|
|||||||
if not info.get("ok"):
|
if not info.get("ok"):
|
||||||
log("无目标期望,退出")
|
log("无目标期望,退出")
|
||||||
return
|
return
|
||||||
s.click_at(info["x"], info["y"])
|
s.human_click(info["x"], info["y"])
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
# 被动监听第一页薪资
|
# 被动监听第一页薪资
|
||||||
reqs: dict[str, str] = {}
|
reqs: dict[str, str] = {}
|
||||||
@@ -78,15 +78,20 @@ def main():
|
|||||||
log("3) 卡片坐标:", pos)
|
log("3) 卡片坐标:", pos)
|
||||||
if pos:
|
if pos:
|
||||||
q = json.loads(pos)
|
q = json.loads(pos)
|
||||||
s.click_at(q["x"], q["y"])
|
s.human_click(q["x"], q["y"])
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
|
|
||||||
# 4) 可信点击立即沟通
|
# 4) 等面板加载,拟人点击立即沟通(重试)
|
||||||
|
xy = None
|
||||||
|
for _ in range(5):
|
||||||
xy = s.eval_js(_btn_xy_js(".op-btn-chat"))
|
xy = s.eval_js(_btn_xy_js(".op-btn-chat"))
|
||||||
|
if xy:
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
log("4) 立即沟通坐标:", xy)
|
log("4) 立即沟通坐标:", xy)
|
||||||
if xy:
|
if xy:
|
||||||
p = json.loads(xy)
|
p = json.loads(xy)
|
||||||
s.click_at(p["x"], p["y"])
|
s.human_click(p["x"], p["y"])
|
||||||
|
|
||||||
# 5) 等弹窗点留在此页
|
# 5) 等弹窗点留在此页
|
||||||
ok = False
|
ok = False
|
||||||
@@ -95,7 +100,7 @@ def main():
|
|||||||
stay = s.eval_js(_STAY_JS)
|
stay = s.eval_js(_STAY_JS)
|
||||||
if stay:
|
if stay:
|
||||||
q = json.loads(stay)
|
q = json.loads(stay)
|
||||||
s.click_at(q["x"], q["y"])
|
s.human_click(q["x"], q["y"])
|
||||||
ok = True
|
ok = True
|
||||||
log("5) 已点留在此页,投递完成")
|
log("5) 已点留在此页,投递完成")
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
"""用 MutationObserver 捕获 chat-block-layer 出现瞬间的内容与时机"""
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from client.browser.applicant import _btn_xy_js, _click_card_js, _select_expect_js, _CARDS_JS
|
||||||
|
from client.browser.cdp_lite import LiteCDP, CDPSession
|
||||||
|
from client.browser.manager import BrowserManager
|
||||||
|
|
||||||
|
OUT = Path(__file__).resolve().parent / "data" / "debug" / "遮罩捕获.txt"
|
||||||
|
|
||||||
|
_lines: list[str] = []
|
||||||
|
|
||||||
|
|
||||||
|
def log(*a):
|
||||||
|
s = " ".join(str(x) for x in a)
|
||||||
|
_lines.append(s)
|
||||||
|
OUT.write_text("\n".join(_lines), encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
OBSERVE = """(() => {
|
||||||
|
if (window.__blkLog) return 'already';
|
||||||
|
window.__blkLog = [];
|
||||||
|
const t0 = Date.now();
|
||||||
|
new MutationObserver(muts => {
|
||||||
|
for (const m of muts) {
|
||||||
|
for (const n of m.addedNodes) {
|
||||||
|
if (n.nodeType === 1 && String(n.className || '').includes('block')) {
|
||||||
|
window.__blkLog.push({dt: Date.now() - t0, cls: String(n.className),
|
||||||
|
html: n.outerHTML.slice(0, 800),
|
||||||
|
text: (n.innerText || '').replace(/\\s+/g, ' ').slice(0, 200)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const n of m.removedNodes) {
|
||||||
|
if (n.nodeType === 1 && String(n.className || '').includes('block')) {
|
||||||
|
window.__blkLog.push({dt: Date.now() - t0, removed: String(n.className)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).observe(document.body, {childList: true, subtree: true});
|
||||||
|
return 'installed';
|
||||||
|
})()"""
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
BrowserManager().ensure_browser_started()
|
||||||
|
lite = LiteCDP()
|
||||||
|
|
||||||
|
# 复用现有 jobs 标签,不新开
|
||||||
|
tabs = [t for t in lite.list_tabs()
|
||||||
|
if t.get("url") == "https://www.zhipin.com/web/geek/jobs"
|
||||||
|
and t.get("webSocketDebuggerUrl")]
|
||||||
|
if not tabs:
|
||||||
|
log("无现有 jobs 标签,退出")
|
||||||
|
return
|
||||||
|
s = CDPSession(tabs[-1]["webSocketDebuggerUrl"])
|
||||||
|
|
||||||
|
log("0) 观察器:", s.eval_js(OBSERVE))
|
||||||
|
info = json.loads(s.eval_js(_select_expect_js("java", "北京")) or "{}")
|
||||||
|
if info.get("ok"):
|
||||||
|
s.human_click(info["x"], info["y"])
|
||||||
|
time.sleep(6)
|
||||||
|
|
||||||
|
cards = s.eval_js(_CARDS_JS) or []
|
||||||
|
if not cards:
|
||||||
|
log("无卡片,退出")
|
||||||
|
return
|
||||||
|
pos = json.loads(s.eval_js(_click_card_js(cards[0]["job_id"])))
|
||||||
|
s.human_click(pos["x"], pos["y"])
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
xy = s.eval_js(_btn_xy_js(".op-btn-chat"))
|
||||||
|
log("1) 立即沟通坐标:", xy)
|
||||||
|
if xy:
|
||||||
|
p = json.loads(xy)
|
||||||
|
s.human_click(p["x"], p["y"])
|
||||||
|
time.sleep(4)
|
||||||
|
|
||||||
|
log("2) block 事件流:", s.eval_js("JSON.stringify(window.__blkLog || [])"))
|
||||||
|
log("3) 发送弹窗:", s.eval_js(_btn_xy_js("a")))
|
||||||
|
log("4) 留在此页按钮数:", s.eval_js(
|
||||||
|
"[...document.querySelectorAll('a,button')].filter(e => e.offsetParent && (e.innerText||'').includes('留在此页')).length"))
|
||||||
|
|
||||||
|
s.close()
|
||||||
|
log("完成")
|
||||||
|
print("捕获完成 ->", OUT)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
"""排查 chat-block-layer 遮罩的结构与来源"""
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from client.browser.applicant import _btn_xy_js, _click_card_js, _select_expect_js, _CARDS_JS
|
||||||
|
from client.browser.cdp_lite import LiteCDP, CDPSession
|
||||||
|
from client.browser.manager import BrowserManager
|
||||||
|
|
||||||
|
OUT = Path(__file__).resolve().parent / "data" / "debug" / "遮罩层排查.txt"
|
||||||
|
|
||||||
|
_lines: list[str] = []
|
||||||
|
|
||||||
|
|
||||||
|
def log(*a):
|
||||||
|
s = " ".join(str(x) for x in a)
|
||||||
|
_lines.append(s)
|
||||||
|
OUT.write_text("\n".join(_lines), encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
BrowserManager().ensure_browser_started()
|
||||||
|
lite = LiteCDP()
|
||||||
|
|
||||||
|
tab = lite.open_tab("https://www.zhipin.com/web/geek/jobs")
|
||||||
|
time.sleep(8)
|
||||||
|
s = CDPSession(tab["webSocketDebuggerUrl"])
|
||||||
|
|
||||||
|
info = json.loads(s.eval_js(_select_expect_js("java", "北京")) or "{}")
|
||||||
|
if info.get("ok"):
|
||||||
|
s.human_click(info["x"], info["y"])
|
||||||
|
time.sleep(6)
|
||||||
|
|
||||||
|
cards = s.eval_js(_CARDS_JS) or []
|
||||||
|
if cards:
|
||||||
|
pos = json.loads(s.eval_js(_click_card_js(cards[0]["job_id"])))
|
||||||
|
s.human_click(pos["x"], pos["y"])
|
||||||
|
time.sleep(1.5)
|
||||||
|
|
||||||
|
log("1) chat-block-layer 全量结构:", s.eval_js("""(() => {
|
||||||
|
const els = [...document.querySelectorAll('.chat-block-layer, [class*=block-layer]')];
|
||||||
|
return els.map(e => JSON.stringify({
|
||||||
|
cls: e.className,
|
||||||
|
可见: !!e.offsetParent,
|
||||||
|
rect: (() => { const r = e.getBoundingClientRect();
|
||||||
|
return {x: r.x, y: r.y, w: r.width, h: r.height}; })(),
|
||||||
|
style: e.getAttribute('style') || '',
|
||||||
|
文本: (e.innerText || '').slice(0, 120),
|
||||||
|
html: e.outerHTML.slice(0, 400)}));
|
||||||
|
})()"""))
|
||||||
|
log("2) 立即沟通按钮祖先链可点击性:", s.eval_js("""(() => {
|
||||||
|
const btn = document.querySelector('.op-btn-chat');
|
||||||
|
if (!btn) return '按钮不存在';
|
||||||
|
const r = btn.getBoundingClientRect();
|
||||||
|
const hit = document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2);
|
||||||
|
return JSON.stringify({
|
||||||
|
按钮rect: {x: r.x, y: r.y, w: r.width, h: r.height},
|
||||||
|
命中元素: hit ? (hit.tagName + '.' + hit.className) : null,
|
||||||
|
按钮href: btn.getAttribute('href')});
|
||||||
|
})()"""))
|
||||||
|
log("3) 页面顶层遮罩候选:", s.eval_js("""(() => {
|
||||||
|
return [...document.querySelectorAll('body > *')]
|
||||||
|
.filter(e => e.offsetParent)
|
||||||
|
.map(e => e.tagName + '.' + String(e.className).slice(0, 60));
|
||||||
|
})()"""))
|
||||||
|
|
||||||
|
s.close()
|
||||||
|
lite.close_tab(tab["id"])
|
||||||
|
log("完成")
|
||||||
|
print("排查完成 ->", OUT)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
"""点击立即沟通后立即观察 chat-block-layer 的出现时机、内容与可关闭性"""
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from client.browser.applicant import _btn_xy_js, _click_card_js, _select_expect_js, _CARDS_JS
|
||||||
|
from client.browser.cdp_lite import LiteCDP, CDPSession
|
||||||
|
from client.browser.manager import BrowserManager
|
||||||
|
|
||||||
|
OUT = Path(__file__).resolve().parent / "data" / "debug" / "遮罩时机排查.txt"
|
||||||
|
|
||||||
|
_lines: list[str] = []
|
||||||
|
|
||||||
|
|
||||||
|
def log(*a):
|
||||||
|
s = " ".join(str(x) for x in a)
|
||||||
|
_lines.append(s)
|
||||||
|
OUT.write_text("\n".join(_lines), encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
SNAP = """(() => {
|
||||||
|
const els = [...document.querySelectorAll('.chat-block-layer, [class*=block], [class*=verify], [class*=slider], [class*=captcha]')];
|
||||||
|
return els.filter(e => e.offsetParent).map(e => JSON.stringify({
|
||||||
|
cls: String(e.className).slice(0, 80),
|
||||||
|
rect: (() => { const r = e.getBoundingClientRect();
|
||||||
|
return [Math.round(r.x), Math.round(r.y), Math.round(r.width), Math.round(r.height)]; })(),
|
||||||
|
文本: (e.innerText || '').replace(/\\s+/g, ' ').slice(0, 200),
|
||||||
|
html: e.outerHTML.slice(0, 600)}));
|
||||||
|
})()"""
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
BrowserManager().ensure_browser_started()
|
||||||
|
lite = LiteCDP()
|
||||||
|
|
||||||
|
tab = lite.open_tab("https://www.zhipin.com/web/geek/jobs")
|
||||||
|
time.sleep(8)
|
||||||
|
s = CDPSession(tab["webSocketDebuggerUrl"])
|
||||||
|
|
||||||
|
info = json.loads(s.eval_js(_select_expect_js("java", "北京")) or "{}")
|
||||||
|
if info.get("ok"):
|
||||||
|
s.human_click(info["x"], info["y"])
|
||||||
|
time.sleep(6)
|
||||||
|
|
||||||
|
cards = s.eval_js(_CARDS_JS) or []
|
||||||
|
if not cards:
|
||||||
|
log("无卡片,退出")
|
||||||
|
return
|
||||||
|
pos = json.loads(s.eval_js(_click_card_js(cards[0]["job_id"])))
|
||||||
|
s.human_click(pos["x"], pos["y"])
|
||||||
|
time.sleep(1.5)
|
||||||
|
|
||||||
|
log("0) 点击前遮罩:", s.eval_js(SNAP))
|
||||||
|
xy = s.eval_js(_btn_xy_js(".op-btn-chat"))
|
||||||
|
p = json.loads(xy)
|
||||||
|
s.human_click(p["x"], p["y"])
|
||||||
|
for delay in (0.3, 0.7, 1.5, 3, 5):
|
||||||
|
time.sleep(delay)
|
||||||
|
log(f"t+{delay}s 遮罩/弹窗:", s.eval_js(SNAP), " 发送弹窗:", s.eval_js(
|
||||||
|
"[...document.querySelectorAll('a')].filter(e => e.offsetParent && (e.innerText||'').includes('留在此页')).length"))
|
||||||
|
|
||||||
|
s.close()
|
||||||
|
lite.close_tab(tab["id"])
|
||||||
|
log("完成")
|
||||||
|
print("排查完成 ->", OUT)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
"""诊断:human_click 点立即沟通后为何无弹窗(查遮罩/新标签/按钮状态)"""
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from client.browser.applicant import (
|
||||||
|
_STAY_JS, _btn_xy_js, _click_card_js, _select_expect_js, _CARDS_JS)
|
||||||
|
from client.browser.cdp_lite import LiteCDP, CDPSession
|
||||||
|
from client.browser.manager import BrowserManager
|
||||||
|
|
||||||
|
OUT = Path(__file__).resolve().parent / "data" / "debug" / "拟人点击诊断.txt"
|
||||||
|
|
||||||
|
_lines: list[str] = []
|
||||||
|
|
||||||
|
|
||||||
|
def log(*a):
|
||||||
|
s = " ".join(str(x) for x in a)
|
||||||
|
_lines.append(s)
|
||||||
|
OUT.write_text("\n".join(_lines), encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
BrowserManager().ensure_browser_started()
|
||||||
|
lite = LiteCDP()
|
||||||
|
|
||||||
|
tabs_before = {t["id"] for t in lite.list_tabs()}
|
||||||
|
|
||||||
|
tab = lite.open_tab("https://www.zhipin.com/web/geek/jobs")
|
||||||
|
time.sleep(8)
|
||||||
|
s = CDPSession(tab["webSocketDebuggerUrl"])
|
||||||
|
s.call("Network.enable")
|
||||||
|
|
||||||
|
info = json.loads(s.eval_js(_select_expect_js("java", "北京")) or "{}")
|
||||||
|
if not info.get("ok"):
|
||||||
|
log("无目标期望,退出")
|
||||||
|
return
|
||||||
|
s.human_click(info["x"], info["y"])
|
||||||
|
time.sleep(6)
|
||||||
|
|
||||||
|
cards = s.eval_js(_CARDS_JS) or []
|
||||||
|
if not cards:
|
||||||
|
log("无卡片,退出")
|
||||||
|
return
|
||||||
|
job_id = cards[0]["job_id"]
|
||||||
|
|
||||||
|
pos = json.loads(s.eval_js(_click_card_js(job_id)))
|
||||||
|
s.human_click(pos["x"], pos["y"])
|
||||||
|
time.sleep(1.5)
|
||||||
|
|
||||||
|
xy = s.eval_js(_btn_xy_js(".op-btn-chat"))
|
||||||
|
log("1) 立即沟通坐标:", xy)
|
||||||
|
p = json.loads(xy)
|
||||||
|
s.human_click(p["x"], p["y"])
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
log("2) 点击点下的元素:", s.eval_js(
|
||||||
|
f"(() => {{ const e = document.elementFromPoint({p['x']}, {p['y']});"
|
||||||
|
" return e ? (e.tagName + '.' + e.className) : 'null'; })()"))
|
||||||
|
log("3) 弹窗检查:", s.eval_js(_STAY_JS))
|
||||||
|
log("4) 页面地址:", s.eval_js("location.href"))
|
||||||
|
log("5) 可见对话框:", s.eval_js("""(() => {
|
||||||
|
const ds = [...document.querySelectorAll('[class*=dialog], [class*=modal], [class*=greet]')]
|
||||||
|
.filter(e => e.offsetParent);
|
||||||
|
return ds.map(e => e.className + ' :: ' + (e.innerText || '').slice(0, 80));
|
||||||
|
})()"""))
|
||||||
|
time.sleep(2)
|
||||||
|
new_tabs = [t for t in lite.list_tabs() if t["id"] not in tabs_before and t["id"] != tab["id"]]
|
||||||
|
log("6) 新增标签:", [t.get("url") for t in new_tabs])
|
||||||
|
|
||||||
|
# 对照组:同位置改用 click_at 再试一次
|
||||||
|
xy2 = s.eval_js(_btn_xy_js(".op-btn-chat"))
|
||||||
|
if xy2:
|
||||||
|
p2 = json.loads(xy2)
|
||||||
|
s.click_at(p2["x"], p2["y"])
|
||||||
|
time.sleep(2)
|
||||||
|
log("7) click_at 对照后弹窗:", s.eval_js(_STAY_JS))
|
||||||
|
|
||||||
|
s.close()
|
||||||
|
lite.close_tab(tab["id"])
|
||||||
|
log("完成")
|
||||||
|
print("诊断完成 ->", OUT)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
"""只读巡检全部 zhipin 标签页(UTF-8 输出到文件,避免控制台编码问题)"""
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from client.browser.cdp_lite import LiteCDP, CDPSession
|
||||||
|
|
||||||
|
OUT = Path(__file__).resolve().parent / "data" / "debug" / "标签巡检.txt"
|
||||||
|
|
||||||
|
lite = LiteCDP()
|
||||||
|
tabs = [t for t in lite.list_tabs()
|
||||||
|
if "zhipin" in (t.get("url") or "") and t.get("webSocketDebuggerUrl")]
|
||||||
|
|
||||||
|
lines = [f"zhipin 标签总数:{len(tabs)}"]
|
||||||
|
for i, t in enumerate(tabs):
|
||||||
|
try:
|
||||||
|
s = CDPSession(t["webSocketDebuggerUrl"])
|
||||||
|
snap = s.eval_js("""(() => JSON.stringify({
|
||||||
|
cards: document.querySelectorAll('.job-card-wrap').length,
|
||||||
|
btn: !!document.querySelector('.op-btn-chat'),
|
||||||
|
block_all: [...document.querySelectorAll('[class*=block-layer], .chat-block-layer')]
|
||||||
|
.map(e => String(e.className) + ' | 可见:' + !!e.offsetParent
|
||||||
|
+ ' | style:' + (e.getAttribute('style') || '')
|
||||||
|
+ ' | rect:' + JSON.stringify((r => [Math.round(r.x), Math.round(r.y), Math.round(r.width), Math.round(r.height)])(e.getBoundingClientRect()))
|
||||||
|
+ ' | 文本:' + (e.innerText || '').replace(/\\s+/g, ' ').slice(0, 150)
|
||||||
|
+ ' | html:' + e.outerHTML.slice(0, 500)),
|
||||||
|
ztop: [...document.querySelectorAll('div')]
|
||||||
|
.filter(e => e.offsetParent && getComputedStyle(e).zIndex > 90)
|
||||||
|
.map(e => String(e.className).slice(0, 50) + ' z=' + getComputedStyle(e).zIndex
|
||||||
|
+ ' :: ' + (e.innerText || '').replace(/\\s+/g, ' ').slice(0, 100)).slice(0, 6),
|
||||||
|
body_top: document.body.innerText.replace(/\\s+/g, ' ').slice(0, 180)
|
||||||
|
}))()""")
|
||||||
|
lines.append(f"[{i}] {t.get('url')}")
|
||||||
|
lines.append(" " + (snap or "null"))
|
||||||
|
s.close()
|
||||||
|
except Exception as e:
|
||||||
|
lines.append(f"[{i}] ERR: {e}")
|
||||||
|
|
||||||
|
OUT.write_text("\n".join(lines), encoding="utf-8")
|
||||||
|
print("巡检完成 ->", OUT)
|
||||||
Reference in New Issue
Block a user