From 46eaa51d6bdc156ce645fcc88c146b171438892a Mon Sep 17 00:00:00 2001 From: lingyunxsh Date: Wed, 26 Aug 2026 12:23:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=8C=8E=E5=A4=B4=E5=BC=80?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/debug_hunter_check.py | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 client/debug_hunter_check.py diff --git a/client/debug_hunter_check.py b/client/debug_hunter_check.py new file mode 100644 index 0000000..74d2b62 --- /dev/null +++ b/client/debug_hunter_check.py @@ -0,0 +1,65 @@ +"""排查:职位卡片中"猎头"标识的真实 DOM,验证猎头识别逻辑""" +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") + + +_DUMP_JS = """(() => { + const cards = [...document.querySelectorAll('.job-card-wrap')]; + const out = {total: cards.length, hits: []}; + cards.forEach((el, i) => { + // 收集卡片内所有自身文本含"猎头"的元素(不含后代文本,定位最小节点) + const own = n => [...n.childNodes] + .filter(c => c.nodeType === 3).map(c => c.textContent).join(''); + const found = [...el.querySelectorAll('*')].filter(n => + own(n).includes('猎头') || (n.children.length === 0 && + (n.innerText || n.textContent || '').includes('猎头'))); + if (found.length || el.innerText.includes('猎头')) { + out.hits.push({ + i, title: (el.querySelector('a.job-name') || {}).innerText || '', + cardHasText: el.innerText.includes('猎头'), + nodes: found.slice(0, 5).map(n => ({ + tag: n.tagName, cls: String(n.className), + text: (n.innerText || '').trim().slice(0, 30), + html: n.outerHTML.replace(/\\s+/g, ' ').slice(0, 220), + })), + // 与 applicant._CARDS_JS 一致的判定结果 + exact: /猎头/.test(el.innerText), + }); + } + }); + return JSON.stringify(out); +})()""" + + +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("卡片总数:", s.eval_js("document.querySelectorAll('.job-card-wrap').length")) + log("猎头标识排查:", s.eval_js(_DUMP_JS)) + + s.close() + lite.close_tab(tab["id"]) + log("完成") + print("排查完成 ->", OUT) + + +if __name__ == "__main__": + main()