86 lines
2.7 KiB
Python
86 lines
2.7 KiB
Python
"""诊断: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()
|