40 lines
1.9 KiB
Python
40 lines
1.9 KiB
Python
"""只读巡检全部 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)
|