修复猎头标识

This commit is contained in:
2026-08-26 12:44:29 +08:00
parent 46eaa51d6b
commit 264cf1604f
5 changed files with 233 additions and 28 deletions
+35 -26
View File
@@ -1,4 +1,7 @@
"""排查:职位卡片中"猎头"标识的真实 DOM,验证猎头识别逻辑"""
"""排查:带搜索词打开职位页,dump 卡片 HTML,定位"猎头"角标真实 DOM
用法:python -m client.debug_hunter_check <搜索词> [城市码] 例:python -m client.debug_hunter_check java 101010100
"""
import sys
import time
from pathlib import Path
@@ -7,6 +10,10 @@ from client.browser.manager import BrowserManager
OUT = Path(__file__).resolve().parent / "data" / "debug" / "猎头标识排查.txt"
# 搜索词 + 城市(命令行可覆盖,用于复现带猎头角标的列表)
QUERY = sys.argv[1] if len(sys.argv) > 1 else "java"
CITY = sys.argv[2] if len(sys.argv) > 2 else "101010100" # 默认北京
_lines: list[str] = []
@@ -16,29 +23,21 @@ def log(*a):
OUT.write_text("\n".join(_lines), encoding="utf-8")
_DUMP_JS = """(() => {
# 概览:每张卡片是否含"猎头"文本 + 收集所有短文本节点(角标候选)
_SUMMARY_JS = """(() => {
const cards = [...document.querySelectorAll('.job-card-wrap')];
const out = {total: cards.length, hits: []};
const out = {total: cards.length, withText: [], shorts: {}};
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),
});
}
if (/猎头/.test(el.innerText)) out.withText.push(i);
[...el.querySelectorAll('*')].forEach(n => {
if (n.children.length === 0) {
const t = (n.innerText || '').trim();
if (t && t.length <= 6) {
const key = t + ' <' + n.tagName.toLowerCase() + ' class="' + n.className + '">';
out.shorts[key] = (out.shorts[key] || 0) + 1;
}
}
});
});
return JSON.stringify(out);
})()"""
@@ -48,12 +47,22 @@ def main():
BrowserManager().ensure_browser_started()
lite = LiteCDP()
tab = lite.open_tab("https://www.zhipin.com/web/geek/jobs")
time.sleep(8)
url = f"https://www.zhipin.com/web/geek/jobs?query={QUERY}&city={CITY}"
tab = lite.open_tab(url)
time.sleep(10)
s = CDPSession(tab["webSocketDebuggerUrl"])
log("卡片总数:", s.eval_js("document.querySelectorAll('.job-card-wrap').length"))
log("猎头标识排查:", s.eval_js(_DUMP_JS))
log("卡片总数/含猎头文本的卡片索引/短文本节点统计:", s.eval_js(_SUMMARY_JS))
n = s.eval_js("document.querySelectorAll('.job-card-wrap').length") or 0
log(f"卡片数:{n},逐卡 dump HTML(前 1800 字符)")
for i in range(int(n)):
html = s.eval_js(f"""(() => {{
const el = document.querySelectorAll('.job-card-wrap')[{i}];
return el ? el.outerHTML.replace(/\\s+/g, ' ').slice(0, 1800) : '';
}})()""")
log(f"===== 卡片 {i} =====")
log(html)
s.close()
lite.close_tab(tab["id"])