This commit is contained in:
2026-08-26 11:41:26 +08:00
parent 17966a342b
commit dd80d265ac
12 changed files with 206 additions and 80 deletions
+19 -2
View File
@@ -54,6 +54,7 @@ class JobCard:
salary: str = ""
jd_text: str = ""
boss_online: bool = False
headhunter: bool = False
# 读取列表卡片(新版 DOM 结构)
@@ -63,7 +64,8 @@ _CARDS_JS = """(() => [...document.querySelectorAll('.job-card-wrap')].map(el =>
const t = s => { const n = el.querySelector(s); return n ? n.innerText.trim() : ''; };
return {job_id: m ? m[1] : '', title: t('.job-name'), company: t('.boss-name'),
location: t('.company-location'), tags: t('.tag-list'),
online: !!el.querySelector('.boss-online-icon')};
online: !!el.querySelector('.boss-online-icon'),
hunter: [...el.querySelectorAll('span,i,em')].some(n => (n.innerText || '').trim() === '猎头')};
}))()"""
# JD 正文(详情页,明文)
@@ -165,7 +167,8 @@ class Applicant:
def start(self, keywords: list[str], city_code: str,
salary_min: int | None, salary_max: int | None,
min_score: int, delay_range: tuple[int, int],
boss_online_only: bool = False, daily_limit: int = 0) -> None:
boss_online_only: bool = False, daily_limit: int = 0,
allow_headhunter: bool = False) -> None:
if self.is_running:
logger.warning("已有投递任务在运行")
return
@@ -184,6 +187,7 @@ class Applicant:
self.stats = {"applied": 0, "skipped": 0, "current": "初始化..."}
self.boss_online_only = boss_online_only
self.daily_limit = daily_limit
self.allow_headhunter = allow_headhunter
self._daily_base = 0
self._thread = threading.Thread(
@@ -306,6 +310,7 @@ class Applicant:
for j in jobs:
if j.get("encryptJobId"):
self._salary_by_id[j["encryptJobId"]] = j.get("salaryDesc") or ""
logger.debug(f"捕获分页响应:{len(jobs)} 个职位,薪资表累计 {len(self._salary_by_id)} 条")
except Exception:
pass
@@ -327,6 +332,7 @@ class Applicant:
company=it.get("company", ""), location=it.get("location", ""),
tags=it.get("tags", ""), salary=it.get("salary", ""),
boss_online=bool(it.get("online")),
headhunter=bool(it.get("hunter")),
))
return cards
@@ -347,6 +353,7 @@ class Applicant:
while applied < max_per_keyword and not self._should_stop():
cards = self._read_cards()
new_cards = [c for c in cards if c.job_id not in processed]
logger.debug(f"列表读取:共 {len(cards)} 张卡片,新增 {len(new_cards)} 张")
if not new_cards:
no_new += 1
if no_new >= 2:
@@ -377,6 +384,8 @@ class Applicant:
pass
self.stats["current"] = f"评估:{card.company} - {card.title}"
logger.debug(f"开始处理卡片:{card.company} - {card.title}"
f" | 薪资={card.salary or '未知'} | Boss在线={card.boss_online}")
# 薪资范围过滤(薪资来自站点分页响应明文)
if salary_min or salary_max:
@@ -393,6 +402,11 @@ class Applicant:
self._report_skip(card, "Boss不在线")
return 0
# 猎头过滤:开关关闭时跳过带猎头标识的职位
if not self.allow_headhunter and card.headhunter:
self._report_skip(card, "猎头职位")
return 0
# 每日上限:达到后结束整个任务
if self.daily_limit and self._daily_base + self.stats["applied"] >= self.daily_limit:
logger.info(f"已达当日投递上限({self.daily_limit}),任务结束")
@@ -431,6 +445,7 @@ class Applicant:
jd = s.eval_js(_JD_JS) or ""
finally:
s.close()
logger.debug(f"JD 抓取完成({len(jd.strip())} 字):{card.title}")
return jd.strip() or f"{card.title} {card.company}"
except Exception:
return f"{card.title} {card.company}"
@@ -450,6 +465,7 @@ class Applicant:
logger.warning(f"未能在列表中选中卡片:{card.title}")
return False
p = json.loads(pos)
logger.debug(f"选中卡片点击坐标:({p['x']}, {p['y']})")
self._sess.human_click(p["x"], p["y"])
time.sleep(1.5)
@@ -464,6 +480,7 @@ class Applicant:
logger.warning(f"右侧面板无立即沟通按钮:{card.title}")
return False
p = json.loads(xy)
logger.debug(f"立即沟通点击坐标:({p['x']}, {p['y']})")
self._sess.human_click(p["x"], p["y"])
# 3. 等待"已向BOSS发送消息"弹窗,点"留在此页"