From 264cf1604fa0b13e7904b66e5fbbce5124533f6f Mon Sep 17 00:00:00 2001 From: lingyunxsh Date: Wed, 26 Aug 2026 12:44:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=8C=8E=E5=A4=B4=E6=A0=87?= =?UTF-8?q?=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build_exe.bat | 2 +- client/browser/applicant.py | 14 +++- client/debug_hunter_check.py | 61 ++++++++++-------- client/debug_hunter_field.py | 63 ++++++++++++++++++ client/debug_hunter_wait.py | 121 +++++++++++++++++++++++++++++++++++ 5 files changed, 233 insertions(+), 28 deletions(-) create mode 100644 client/debug_hunter_field.py create mode 100644 client/debug_hunter_wait.py diff --git a/build_exe.bat b/build_exe.bat index b4ae19b..e26ef0a 100644 --- a/build_exe.bat +++ b/build_exe.bat @@ -7,7 +7,7 @@ REM 每次升级改 APP_VERSION,避免与正在运行的旧版本目录冲突 REM 使用:把整个文件夹拷到目标机器(或压缩成 zip 发送), REM 双击文件夹里的 Boss直聘AI投递-%APP_VERSION%.exe 运行。 REM ============================================================ -set APP_VERSION=1.1 +set APP_VERSION=1.2 echo [1/2] 安装打包依赖... pip install pyinstaller PySide6 --quiet diff --git a/client/browser/applicant.py b/client/browser/applicant.py index 69ccb86..e081a85 100644 --- a/client/browser/applicant.py +++ b/client/browser/applicant.py @@ -167,6 +167,8 @@ class Applicant: self._tab: dict | None = None self._sess: CDPSession | None = None self._salary_by_id: dict[str, str] = {} + # 招聘者职位(来自分页响应 bossTitle,猎头判定依据) + self._boss_title_by_id: dict[str, str] = {} # 公司黑名单(每次任务开始时从云端拉取) self._blacklist: set[str] = set() @@ -328,6 +330,11 @@ class Applicant: for j in jobs: if j.get("encryptJobId"): 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)} 条") except Exception: pass @@ -345,6 +352,10 @@ class Applicant: if not it.get("job_id"): continue 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( job_id=it.get("job_id", ""), title=it.get("title", ""), company=it.get("company", ""), location=it.get("location", ""), @@ -409,7 +420,8 @@ class Applicant: self.stats["current"] = f"评估:{card.company} - {card.title}" logger.debug(f"开始处理卡片:{card.company} - {card.title}" 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: diff --git a/client/debug_hunter_check.py b/client/debug_hunter_check.py index 74d2b62..562f1e4 100644 --- a/client/debug_hunter_check.py +++ b/client/debug_hunter_check.py @@ -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"]) diff --git a/client/debug_hunter_field.py b/client/debug_hunter_field.py new file mode 100644 index 0000000..fb3baf7 --- /dev/null +++ b/client/debug_hunter_field.py @@ -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() diff --git a/client/debug_hunter_wait.py b/client/debug_hunter_wait.py new file mode 100644 index 0000000..3e1fe51 --- /dev/null +++ b/client/debug_hunter_wait.py @@ -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()