70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
"""点击立即沟通后立即观察 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()
|