64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
"""排查: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()
|