基本完成
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user