35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
"""排查:期望项 .expect-item 的 class 结构(含选中态标记)"""
|
||
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"
|
||
|
||
_JS = """JSON.stringify([...document.querySelectorAll('.expect-item')].map(e => ({
|
||
cls: String(e.className),
|
||
text: (e.innerText || '').trim().slice(0, 50),
|
||
html: e.outerHTML.replace(/\\s+/g, ' ').slice(0, 300),
|
||
})))"""
|
||
|
||
|
||
def main():
|
||
BrowserManager().ensure_browser_started()
|
||
lite = LiteCDP()
|
||
tab = lite.open_tab("https://www.zhipin.com/web/geek/jobs")
|
||
time.sleep(8)
|
||
s = CDPSession(tab["webSocketDebuggerUrl"])
|
||
raw = s.eval_js(_JS)
|
||
items = json.loads(raw or "[]")
|
||
lines = [json.dumps(it, ensure_ascii=False) for it in items]
|
||
OUT.write_text("\n".join(lines) or "(未找到 .expect-item)", encoding="utf-8")
|
||
s.close()
|
||
lite.close_tab(tab["id"])
|
||
print("完成 ->", OUT)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|