修复猎头标识

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
+1 -1
View File
@@ -7,7 +7,7 @@ REM 每次升级改 APP_VERSION,避免与正在运行的旧版本目录冲突
REM 使用:把整个文件夹拷到目标机器(或压缩成 zip 发送), REM 使用:把整个文件夹拷到目标机器(或压缩成 zip 发送),
REM 双击文件夹里的 Boss直聘AI投递-%APP_VERSION%.exe 运行。 REM 双击文件夹里的 Boss直聘AI投递-%APP_VERSION%.exe 运行。
REM ============================================================ REM ============================================================
set APP_VERSION=1.1 set APP_VERSION=1.2
echo [1/2] 安装打包依赖... echo [1/2] 安装打包依赖...
pip install pyinstaller PySide6 --quiet pip install pyinstaller PySide6 --quiet
+13 -1
View File
@@ -167,6 +167,8 @@ class Applicant:
self._tab: dict | None = None self._tab: dict | None = None
self._sess: CDPSession | None = None self._sess: CDPSession | None = None
self._salary_by_id: dict[str, str] = {} self._salary_by_id: dict[str, str] = {}
# 招聘者职位(来自分页响应 bossTitle,猎头判定依据)
self._boss_title_by_id: dict[str, str] = {}
# 公司黑名单(每次任务开始时从云端拉取) # 公司黑名单(每次任务开始时从云端拉取)
self._blacklist: set[str] = set() self._blacklist: set[str] = set()
@@ -328,6 +330,11 @@ class Applicant:
for j in jobs: for j in jobs:
if j.get("encryptJobId"): if j.get("encryptJobId"):
self._salary_by_id[j["encryptJobId"]] = j.get("salaryDesc") or "" self._salary_by_id[j["encryptJobId"]] = j.get("salaryDesc") or ""
# 猎头判定依据:招聘者职位(如"猎头顾问");goldHunter 为金猎头标识
title = j.get("bossTitle") or ""
if j.get("goldHunter"):
title = title or "猎头"
self._boss_title_by_id[j["encryptJobId"]] = title
logger.debug(f"捕获分页响应:{len(jobs)} 个职位,薪资表累计 {len(self._salary_by_id)} 条") logger.debug(f"捕获分页响应:{len(jobs)} 个职位,薪资表累计 {len(self._salary_by_id)} 条")
except Exception: except Exception:
pass pass
@@ -345,6 +352,10 @@ class Applicant:
if not it.get("job_id"): if not it.get("job_id"):
continue continue
it["salary"] = self._salary_by_id.get(it["job_id"], "") it["salary"] = self._salary_by_id.get(it["job_id"], "")
# 猎头判定:优先用分页响应 bossTitle(页面卡片上无可靠标识)
boss_title = self._boss_title_by_id.get(it["job_id"], "")
it["hunter"] = "猎头" in boss_title or bool(it.get("hunter"))
it["boss_title"] = boss_title
cards.append(JobCard( cards.append(JobCard(
job_id=it.get("job_id", ""), title=it.get("title", ""), job_id=it.get("job_id", ""), title=it.get("title", ""),
company=it.get("company", ""), location=it.get("location", ""), company=it.get("company", ""), location=it.get("location", ""),
@@ -409,7 +420,8 @@ class Applicant:
self.stats["current"] = f"评估:{card.company} - {card.title}" self.stats["current"] = f"评估:{card.company} - {card.title}"
logger.debug(f"开始处理卡片:{card.company} - {card.title}" logger.debug(f"开始处理卡片:{card.company} - {card.title}"
f" | 薪资={card.salary or '未知'} | Boss在线={card.boss_online}" f" | 薪资={card.salary or '未知'} | Boss在线={card.boss_online}"
f" | 猎头={card.headhunter}") f" | 猎头={card.headhunter}"
f" | 招聘者={self._boss_title_by_id.get(card.job_id, '未知')}")
# 薪资范围过滤(薪资来自站点分页响应明文) # 薪资范围过滤(薪资来自站点分页响应明文)
if salary_min or salary_max: if salary_min or salary_max:
+34 -25
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 import time
from pathlib import Path from pathlib import Path
@@ -7,6 +10,10 @@ from client.browser.manager import BrowserManager
OUT = Path(__file__).resolve().parent / "data" / "debug" / "猎头标识排查.txt" 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] = [] _lines: list[str] = []
@@ -16,29 +23,21 @@ def log(*a):
OUT.write_text("\n".join(_lines), encoding="utf-8") OUT.write_text("\n".join(_lines), encoding="utf-8")
_DUMP_JS = """(() => { # 概览:每张卡片是否含"猎头"文本 + 收集所有短文本节点(角标候选)
_SUMMARY_JS = """(() => {
const cards = [...document.querySelectorAll('.job-card-wrap')]; const cards = [...document.querySelectorAll('.job-card-wrap')];
const out = {total: cards.length, hits: []}; const out = {total: cards.length, withText: [], shorts: {}};
cards.forEach((el, i) => { cards.forEach((el, i) => {
// 收集卡片内所有自身文本含"猎头"的元素(不含后代文本,定位最小节点) if (/猎头/.test(el.innerText)) out.withText.push(i);
const own = n => [...n.childNodes] [...el.querySelectorAll('*')].forEach(n => {
.filter(c => c.nodeType === 3).map(c => c.textContent).join(''); if (n.children.length === 0) {
const found = [...el.querySelectorAll('*')].filter(n => const t = (n.innerText || '').trim();
own(n).includes('猎头') || (n.children.length === 0 && if (t && t.length <= 6) {
(n.innerText || n.textContent || '').includes('猎头'))); const key = t + ' <' + n.tagName.toLowerCase() + ' class="' + n.className + '">';
if (found.length || el.innerText.includes('猎头')) { out.shorts[key] = (out.shorts[key] || 0) + 1;
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); return JSON.stringify(out);
})()""" })()"""
@@ -48,12 +47,22 @@ def main():
BrowserManager().ensure_browser_started() BrowserManager().ensure_browser_started()
lite = LiteCDP() lite = LiteCDP()
tab = lite.open_tab("https://www.zhipin.com/web/geek/jobs") url = f"https://www.zhipin.com/web/geek/jobs?query={QUERY}&city={CITY}"
time.sleep(8) tab = lite.open_tab(url)
time.sleep(10)
s = CDPSession(tab["webSocketDebuggerUrl"]) s = CDPSession(tab["webSocketDebuggerUrl"])
log("卡片总数:", s.eval_js("document.querySelectorAll('.job-card-wrap').length")) log("卡片总数/含猎头文本的卡片索引/短文本节点统计:", s.eval_js(_SUMMARY_JS))
log("猎头标识排查:", s.eval_js(_DUMP_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() s.close()
lite.close_tab(tab["id"]) lite.close_tab(tab["id"])
+63
View File
@@ -0,0 +1,63 @@
"""排查:list.json 分页响应中每个职位的字段结构,找招聘者职位(猎头顾问)字段"""
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 main():
BrowserManager().ensure_browser_started()
lite = LiteCDP()
tab = lite.open_tab("https://www.zhipin.com/web/geek/jobs?query=java&city=101010100")
time.sleep(8)
s = CDPSession(tab["webSocketDebuggerUrl"])
s.call("Network.enable")
# 触发一次滚动,让站点请求分页/列表接口
s.eval_js("window.scrollBy(0, 600)")
time.sleep(2)
s.eval_js("window.scrollBy(0, 600)")
dumped = 0
for msg in s.pump(6):
if msg.get("method") != "Network.responseReceived":
continue
url = msg["params"]["response"]["url"]
if not any(k in url for k in ("joblist", "job/list", "search", "recommend")):
continue
rid = msg["params"]["requestId"]
try:
body = s.call("Network.getResponseBody", {"requestId": rid}).get("body", "")
jobs = json.loads(body).get("zpData", {}).get("jobList") or []
except Exception as e:
log(f"响应解析失败:{e}")
continue
log(f"接口:{url[:120]},职位数:{len(jobs)}")
for j in jobs[:6]:
log("----- 职位字段 -----")
log(json.dumps(j, ensure_ascii=False)[:1200])
dumped += 1
if dumped >= 2:
break
s.close()
lite.close_tab(tab["id"])
log("完成")
print("排查完成 ->", OUT)
if __name__ == "__main__":
main()
+121
View File
@@ -0,0 +1,121 @@
"""排查猎头角标/筛选框真实 DOM(交互式):
脚本打开 Boss 职位页并保持标签页打开,你手动点开页面上"猎头"相关的方框,
脚本每 5 秒自动抓一次页面状态(所有自身文本含"猎头"的元素 + 命中的卡片 HTML),
连续 3 轮稳定抓到后自动结束并关闭标签页;最多等 4 分钟。
用法:python -m client.debug_hunter_wait [搜索词] [城市码]
结果:client/data/debug/猎头点击排查.txt
"""
import sys
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"
QUERY = sys.argv[1] if len(sys.argv) > 1 else ""
CITY = sys.argv[2] if len(sys.argv) > 2 else ""
MAX_ROUNDS = 48 # 48 x 5s = 4 分钟
INTERVAL = 5 # 每轮间隔秒数
_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")
# 全页面中"自身文本"含猎头的元素(定位最小节点:角标/筛选框文字本身)
_OWN_TEXT_JS = """(() => {
const out = [];
for (const n of document.querySelectorAll('*')) {
const own = [...n.childNodes]
.filter(c => c.nodeType === 3)
.map(c => c.textContent).join('').trim();
if (own.includes('猎头')) {
out.push({
tag: n.tagName, cls: String(n.className).slice(0, 120),
text: own.slice(0, 40),
html: n.outerHTML.replace(/\\s+/g, ' ').slice(0, 350),
});
}
}
return JSON.stringify(out.slice(0, 20));
})()"""
_SUMMARY_JS = """(() => {
const cards = [...document.querySelectorAll('.job-card-wrap')];
return JSON.stringify({
total: cards.length,
withText: cards.reduce((acc, el, i) =>
(/猎头/.test(el.innerText) ? acc.concat(i) : acc), []),
});
})()"""
def main():
BrowserManager().ensure_browser_started()
lite = LiteCDP()
url = "https://www.zhipin.com/web/geek/jobs"
if QUERY:
url += f"?query={QUERY}"
if CITY:
url += f"&city={CITY}"
tab = lite.open_tab(url)
print(f"页面已打开:{url}")
print(">>> 请在页面上点开猎头相关的方框/筛选,脚本会自动抓取,抓稳后自动结束 <<<")
time.sleep(8)
s = CDPSession(tab["webSocketDebuggerUrl"])
s.call("Network.enable")
stable = 0
dumped_card = False
for r in range(1, MAX_ROUNDS + 1):
try:
summary = s.eval_js(_SUMMARY_JS)
hits = s.eval_js(_OWN_TEXT_JS)
except Exception as e:
log(f"----- 第{r}轮:页面状态读取失败({e}),等待重试 -----")
time.sleep(INTERVAL)
continue
log(f"----- 第{r}轮 -----")
log("卡片概况(total/withText索引):", summary)
log("自身文本含猎头的元素:", hits)
found = (hits not in ("[]", "", None)) or ('"withText":[]' not in (summary or ""))
if found:
stable += 1
# 命中后 dump 第一张含猎头文本的卡片完整 HTML(只 dump 一次)
if not dumped_card:
card_html = s.eval_js("""(() => {
const el = [...document.querySelectorAll('.job-card-wrap')]
.find(c => /猎头/.test(c.innerText));
return el ? el.outerHTML.replace(/\\s+/g, ' ').slice(0, 2500) : '';
})()""")
if card_html:
log("===== 含猎头文本的卡片 HTML =====")
log(card_html)
dumped_card = True
if stable >= 3:
log(f"连续 {stable} 轮抓到猎头元素,排查完成")
break
else:
stable = 0
time.sleep(INTERVAL)
s.close()
lite.close_tab(tab["id"])
log("完成")
print("排查完成 ->", OUT)
if __name__ == "__main__":
main()