基本完成
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""排查:点击期望后卡片容器的真实 DOM 状态"""
|
||||
import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from client.browser.applicant import _select_expect_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()
|
||||
|
||||
tab = lite.open_tab("https://www.zhipin.com/web/geek/jobs")
|
||||
time.sleep(8)
|
||||
s = CDPSession(tab["webSocketDebuggerUrl"])
|
||||
|
||||
log("0) 初始卡片数:", s.eval_js("document.querySelectorAll('.job-card-wrap').length"))
|
||||
|
||||
log("1) 期望点击:", s.eval_js(_select_expect_js("java", "北京")))
|
||||
for i in range(6):
|
||||
time.sleep(1)
|
||||
log(f"2) 第{i + 1}秒:", s.eval_js("""JSON.stringify({
|
||||
wrap: document.querySelectorAll('.job-card-wrap').length,
|
||||
body: document.querySelectorAll('.job-card-body').length,
|
||||
left: document.querySelectorAll('.job-card-left').length,
|
||||
列表容器: (() => { const c = document.querySelector('.job-list-content, .job-list, .search-job-result, .recommend-job-list, .card-list'); return c ? String(c.className) : null; })()})"""))
|
||||
|
||||
log("3) 列表区域片段:", s.eval_js("""(() => {
|
||||
const c = document.querySelector('.job-card-wrap') || document.querySelector('.job-list-content') || document.querySelector('.job-list');
|
||||
let p = c; for (let i = 0; i < 2 && p && p.parentElement; i++) p = p.parentElement;
|
||||
const el = p || document.body;
|
||||
return el.outerHTML.replace(/\\s+/g, ' ').slice(0, 1200);
|
||||
})()"""))
|
||||
|
||||
s.close()
|
||||
lite.close_tab(tab["id"])
|
||||
log("完成")
|
||||
print("排查完成 ->", OUT)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user