73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
"""排查二:可信点击期望项后的真实视图状态(期望栏 class / 可见卡片 / 容器)"""
|
|
import json
|
|
import time
|
|
from pathlib import Path
|
|
|
|
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 状态(s):
|
|
return s.eval_js("""JSON.stringify({
|
|
地址: location.href,
|
|
期望栏: [...document.querySelectorAll('.expect-item')].map(e => ({
|
|
t: (e.querySelector('.text-content') || {}).innerText,
|
|
cls: String(e.className)})),
|
|
推荐tab: String((document.querySelector('.synthesis') || {className: ''}).className),
|
|
可见wrap: [...document.querySelectorAll('.job-card-wrap')].filter(e => e.offsetParent).length,
|
|
全部wrap: document.querySelectorAll('.job-card-wrap').length,
|
|
可见列表容器: (() => {
|
|
const cands = ['.rec-job-list', '.search-job-result', '.expect-job-list', '.job-list'];
|
|
return cands.map(c => { const e = document.querySelector(c);
|
|
return e && e.offsetParent ? c : null; }).filter(Boolean);
|
|
})()})""")
|
|
|
|
|
|
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"])
|
|
|
|
log("1) 点击前:", 状态(s))
|
|
|
|
xy = s.eval_js("""(() => {
|
|
const el = [...document.querySelectorAll('.expect-item')]
|
|
.find(e => ((e.querySelector('.text-content') || {}).innerText || '').endsWith('(北京)'));
|
|
if (!el) return null;
|
|
const r = el.getBoundingClientRect();
|
|
return JSON.stringify({x: r.x + r.width / 2, y: r.y + r.height / 2});
|
|
})()""")
|
|
log("2) 期望坐标:", xy)
|
|
p = json.loads(xy)
|
|
s.click_at(p["x"], p["y"])
|
|
time.sleep(5)
|
|
|
|
log("3) 可信点击后:", 状态(s))
|
|
log("4) 可见列表片段:", s.eval_js("""(() => {
|
|
const el = [...document.querySelectorAll('.job-card-wrap')].find(e => e.offsetParent)
|
|
|| document.querySelector('.rec-job-list') || document.body;
|
|
return el.outerHTML.replace(/\\s+/g, ' ').slice(0, 900);
|
|
})()"""))
|
|
|
|
s.close()
|
|
lite.close_tab(tab["id"])
|
|
log("完成")
|
|
print("排查完成 ->", OUT)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|