haha
This commit is contained in:
83
1.py
83
1.py
@@ -9,6 +9,7 @@ from __future__ import annotations
|
|||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# 保证从项目根目录运行时可导入 worker 包
|
# 保证从项目根目录运行时可导入 worker 包
|
||||||
@@ -17,11 +18,11 @@ if str(_ROOT) not in sys.path:
|
|||||||
sys.path.insert(0, str(_ROOT))
|
sys.path.insert(0, str(_ROOT))
|
||||||
|
|
||||||
# ---------- 选择控制对象 ----------
|
# ---------- 选择控制对象 ----------
|
||||||
USE_LOCAL_CHROME = True # True=本地谷歌 Chrome,False=比特浏览器
|
USE_LOCAL_CHROME = True # True=本地谷歌 Chrome,False=比特浏览器
|
||||||
|
|
||||||
# 本地谷歌 Chrome 配置(仅当 USE_LOCAL_CHROME=True 时生效)
|
# 本地谷歌 Chrome 配置(仅当 USE_LOCAL_CHROME=True 时生效)
|
||||||
CHROME_DEBUG_PORT = 9222 # 调试端口;若为 None 则由脚本自动启动 Chrome
|
CHROME_DEBUG_PORT = 9222 # 调试端口;若为 None 则由脚本自动启动 Chrome
|
||||||
CHROME_PATH = None # 例如 r"C:\Program Files\Google\Chrome\Application\chrome.exe",None 用系统默认
|
CHROME_PATH = None # 例如 r"C:\Program Files\Google\Chrome\Application\chrome.exe",None 用系统默认
|
||||||
|
|
||||||
# 比特浏览器配置(仅当 USE_LOCAL_CHROME=False 时生效)
|
# 比特浏览器配置(仅当 USE_LOCAL_CHROME=False 时生效)
|
||||||
BIT_API_BASE = "http://127.0.0.1:54345"
|
BIT_API_BASE = "http://127.0.0.1:54345"
|
||||||
@@ -65,7 +66,7 @@ def _connect_bit_browser():
|
|||||||
return ChromiumPage(addr_or_opts=co)
|
return ChromiumPage(addr_or_opts=co)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main(filters):
|
||||||
from DrissionPage.errors import NoRectError
|
from DrissionPage.errors import NoRectError
|
||||||
|
|
||||||
if USE_LOCAL_CHROME:
|
if USE_LOCAL_CHROME:
|
||||||
@@ -73,25 +74,33 @@ def main():
|
|||||||
else:
|
else:
|
||||||
page = _connect_bit_browser()
|
page = _connect_bit_browser()
|
||||||
|
|
||||||
|
# 先启动监听再执行动作,否则拿不到数据包(见 DP 文档)
|
||||||
page.listen.start('wapi/zpjob/rec/geek/list')
|
page.listen.start('wapi/zpjob/rec/geek/list')
|
||||||
|
|
||||||
# 示例:打开一个页面(可选)
|
if filters:
|
||||||
page.get("https://www.zhipin.com/web/chat/recommend")
|
main2(page, filters)
|
||||||
res = page.listen.wait()
|
# 有筛选时:page.get 会触发第 1 个 geek/list,点「确定」触发第 2 个;取最后一个才是筛选后的结果
|
||||||
|
packets = page.listen.wait(count=2, timeout=30)
|
||||||
|
res = packets[-1] if packets else None
|
||||||
|
else:
|
||||||
|
page.get("https://www.zhipin.com/web/chat/recommend")
|
||||||
|
res = page.listen.wait(timeout=30)
|
||||||
|
|
||||||
|
if not res:
|
||||||
|
raise RuntimeError("未捕获到目标请求 wapi/zpjob/rec/geek/list")
|
||||||
|
|
||||||
for i in res.response.body["zpData"]["geekList"]:
|
for i in res.response.body["zpData"]["geekList"]:
|
||||||
print(i)
|
print(i)
|
||||||
|
|
||||||
geekName = i["geekCard"]["geekName"] # 姓名
|
geekName = i["geekCard"]["geekName"] # 姓名
|
||||||
geekDegree = i["geekCard"]["geekDegree"] # 学历
|
geekDegree = i["geekCard"]["geekDegree"] # 学历
|
||||||
expectPositionName = i["geekCard"]["expectPositionName"] #期待职位
|
expectPositionName = i["geekCard"]["expectPositionName"] # 期待职位
|
||||||
expectLocationName = i["geekCard"]["expectLocationName"] # 地区
|
expectLocationName = i["geekCard"]["expectLocationName"] # 地区
|
||||||
applyStatusDesc = i["geekCard"]["applyStatusDesc"] # 当前状态离职0随时到岗之类的
|
applyStatusDesc = i["geekCard"]["applyStatusDesc"] # 当前状态离职0随时到岗之类的
|
||||||
ageDesc = i["geekCard"]["ageDesc"] # 年龄
|
ageDesc = i["geekCard"]["ageDesc"] # 年龄
|
||||||
lowSalary = i["geekCard"]["lowSalary"] # 最低要求工资
|
lowSalary = i["geekCard"]["lowSalary"] # 最低要求工资
|
||||||
highSalary = i["geekCard"]["highSalary"] # 最高要求工资
|
highSalary = i["geekCard"]["highSalary"] # 最高要求工资
|
||||||
|
|
||||||
|
|
||||||
"""三个动作:1. 找到姓名 2. 滚动到那里 3. 点击打招呼"""
|
"""三个动作:1. 找到姓名 2. 滚动到那里 3. 点击打招呼"""
|
||||||
try:
|
try:
|
||||||
container = page.get_frame("recommendFrame")
|
container = page.get_frame("recommendFrame")
|
||||||
@@ -99,7 +108,7 @@ def main():
|
|||||||
container = page
|
container = page
|
||||||
|
|
||||||
# 1. 找到这个姓名
|
# 1. 找到这个姓名
|
||||||
name_ele = container.ele(f'x://span[contains(text(),"{geekName}")]', timeout=10)
|
name_ele = container.ele(f'x://span[contains(text(),"{geekName}")]', timeout=5)
|
||||||
if not name_ele:
|
if not name_ele:
|
||||||
name_ele = container.ele(f'x://span[text()="{geekName}"]', timeout=2)
|
name_ele = container.ele(f'x://span[text()="{geekName}"]', timeout=2)
|
||||||
if not name_ele:
|
if not name_ele:
|
||||||
@@ -115,17 +124,65 @@ def main():
|
|||||||
for _ in range(8):
|
for _ in range(8):
|
||||||
if not parent:
|
if not parent:
|
||||||
break
|
break
|
||||||
greet_btn = parent.ele('x://span[text()="打招呼"]', timeout=0.5) or parent.ele('x://*[contains(text(),"打招呼")]', timeout=0.5)
|
greet_btn = parent.ele('x://span[text()="打招呼"]', timeout=0.5) or parent.ele(
|
||||||
|
'x://*[contains(text(),"打招呼")]', timeout=0.5)
|
||||||
if greet_btn:
|
if greet_btn:
|
||||||
break
|
break
|
||||||
parent = parent.parent()
|
parent = parent.parent()
|
||||||
if not greet_btn:
|
if not greet_btn:
|
||||||
greet_btn = container.ele('x://span[text()="打招呼"]', timeout=2) or container.ele('x://*[contains(text(),"打招呼")]', timeout=1)
|
greet_btn = container.ele('x://span[text()="打招呼"]', timeout=2) or container.ele(
|
||||||
|
'x://*[contains(text(),"打招呼")]', timeout=1)
|
||||||
if not greet_btn:
|
if not greet_btn:
|
||||||
raise Exception("未找到「打招呼」按钮")
|
raise Exception("未找到「打招呼」按钮")
|
||||||
greet_btn.click(by_js=True)
|
greet_btn.click(by_js=True)
|
||||||
|
|
||||||
|
|
||||||
|
def main1():
|
||||||
|
if USE_LOCAL_CHROME:
|
||||||
|
page = _connect_local_chrome()
|
||||||
|
else:
|
||||||
|
page = _connect_bit_browser()
|
||||||
|
|
||||||
|
page.listen.start('wapi/zpblock/recommend/filters')
|
||||||
|
|
||||||
|
# 示例:打开一个页面(可选)
|
||||||
|
page.get("https://www.zhipin.com/web/chat/recommend")
|
||||||
|
res = page.listen.wait()
|
||||||
|
|
||||||
|
filters = {}
|
||||||
|
for i in res.response.body["zpData"]["vipFilter"]["filters"]:
|
||||||
|
print(i)
|
||||||
|
|
||||||
|
if i["name"] == "年龄":
|
||||||
|
print(i["start"])
|
||||||
|
print(i["end"])
|
||||||
|
|
||||||
|
filters[i["name"]] = range(int(i["start"]), int(i["end"]) + 1)
|
||||||
|
else:
|
||||||
|
datas = []
|
||||||
|
for i1 in i["options"]:
|
||||||
|
print(i1["name"])
|
||||||
|
datas.append(i1["name"])
|
||||||
|
|
||||||
|
filters[i["name"]] = datas
|
||||||
|
|
||||||
|
print(filters)
|
||||||
|
|
||||||
|
|
||||||
|
def main2(page, filters):
|
||||||
|
"""在同一 page 上打开推荐页、点筛选、选条件、点确定;点击确定后会触发 wapi/zpjob/rec/geek/list,由 main() 的 listen 捕获。"""
|
||||||
|
page.get("https://www.zhipin.com/web/chat/recommend")
|
||||||
|
|
||||||
|
page.ele("x://*[contains(text(),'筛选')]").click()
|
||||||
|
time.sleep(3)
|
||||||
|
for i in filters:
|
||||||
|
page.ele(f"x://*[contains(text(),'{i}')]").click()
|
||||||
|
time.sleep(random.random() * 2)
|
||||||
|
|
||||||
|
page.ele("x://*[contains(text(),'确定')]").click()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main(filters=["初中及以下", '离职-随时到岗'])
|
||||||
|
# main1()
|
||||||
|
# main2()
|
||||||
|
|||||||
46
自动化.py
46
自动化.py
@@ -24,6 +24,47 @@ BROWSER_NAME = "测试2" # 例如 "第一个" 或 "主账号"
|
|||||||
BROWSER_ID = None # 若已知窗口 ID,可直接填
|
BROWSER_ID = None # 若已知窗口 ID,可直接填
|
||||||
|
|
||||||
|
|
||||||
|
def do_recommend_filter(page):
|
||||||
|
"""
|
||||||
|
在推荐牛人页面:点开右上角筛选 -> 弹窗内完成筛选操作 -> 点击确认。
|
||||||
|
筛选 UI 在 iframe recommendFrame 内(推荐牛人 / recommend-v2)。
|
||||||
|
"""
|
||||||
|
time.sleep(1.5) # 等待 iframe 加载
|
||||||
|
# 获取推荐牛人 iframe(name=recommendFrame)
|
||||||
|
frame = page.get_frame("@name=recommendFrame")
|
||||||
|
if not frame:
|
||||||
|
frame = page.get_frame(1) # fallback:第一个 iframe
|
||||||
|
if not frame:
|
||||||
|
print("未找到推荐牛人 iframe,跳过筛选")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 1. 点击右上角「筛选」,打开弹窗
|
||||||
|
filter_btn = frame.ele("x://span[text()='筛选']", timeout=3) or frame.ele(
|
||||||
|
"x://*[contains(text(),'筛选')]", timeout=2
|
||||||
|
)
|
||||||
|
if not filter_btn:
|
||||||
|
print("未找到「筛选」按钮,跳过筛选")
|
||||||
|
return
|
||||||
|
filter_btn.click(by_js=True)
|
||||||
|
time.sleep(0.8)
|
||||||
|
|
||||||
|
# 2. 弹窗内完成筛选(按需在此增加具体筛选项点击,例如学历、经验、期望职位等)
|
||||||
|
# 若无需改任何条件,可保持默认,直接点确认即可。
|
||||||
|
|
||||||
|
# 3. 点击弹窗中的「确认」
|
||||||
|
confirm = (
|
||||||
|
frame.ele("x://span[text()='确认']", timeout=3)
|
||||||
|
or frame.ele("x://span[text()='确定']", timeout=2)
|
||||||
|
or frame.ele("x://*[contains(text(),'确认')]", timeout=2)
|
||||||
|
)
|
||||||
|
if not confirm:
|
||||||
|
print("未找到「确认」按钮")
|
||||||
|
return
|
||||||
|
confirm.click(by_js=True)
|
||||||
|
time.sleep(0.5)
|
||||||
|
print("推荐牛人筛选已确认")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
from DrissionPage import ChromiumPage, ChromiumOptions
|
from DrissionPage import ChromiumPage, ChromiumOptions
|
||||||
from DrissionPage.errors import NoRectError
|
from DrissionPage.errors import NoRectError
|
||||||
@@ -46,10 +87,13 @@ def main():
|
|||||||
|
|
||||||
page.listen.start('wapi/zprelation/friend/getBossFriendListV2')
|
page.listen.start('wapi/zprelation/friend/getBossFriendListV2')
|
||||||
|
|
||||||
# 示例:打开一个页面(可选)
|
# 打开推荐牛人/聊天页
|
||||||
page.get("https://www.zhipin.com/web/chat/index")
|
page.get("https://www.zhipin.com/web/chat/index")
|
||||||
res = page.listen.wait()
|
res = page.listen.wait()
|
||||||
|
|
||||||
|
# 执行推荐牛人筛选:点开右上角筛选 -> 弹窗内完成筛选 -> 点击确认
|
||||||
|
do_recommend_filter(page)
|
||||||
|
|
||||||
for i in res.response.body["zpData"]["friendList"]:
|
for i in res.response.body["zpData"]["friendList"]:
|
||||||
print(i)
|
print(i)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user