60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""按姓名找到求职人 → 滚动到该人 → 点击打招呼(DrissionPage,三个动作)"""
|
|||
|
|
import time
|
|||
|
|
|
|||
|
|
# 求职人姓名
|
|||
|
|
姓名 = "王先生"
|
|||
|
|
|
|||
|
|
|
|||
|
|
def do_greet(page, 姓名, container=None):
|
|||
|
|
"""三个动作:1. 找到姓名 2. 滚动到那里 3. 点击打招呼"""
|
|||
|
|
if container is None:
|
|||
|
|
try:
|
|||
|
|
container = page.get_frame("recommendFrame")
|
|||
|
|
except Exception:
|
|||
|
|
container = page
|
|||
|
|
|
|||
|
|
# 1. 找到这个姓名
|
|||
|
|
name_ele = container.ele(f'x://span[contains(text(),"{姓名}")]', timeout=10)
|
|||
|
|
if not name_ele:
|
|||
|
|
name_ele = container.ele(f'x://span[text()="{姓名}"]', timeout=2)
|
|||
|
|
if not name_ele:
|
|||
|
|
raise Exception(f"未找到姓名:{姓名}")
|
|||
|
|
|
|||
|
|
# 2. 滚动到那里
|
|||
|
|
name_ele.run_js("this.scrollIntoView({block: 'center', behavior: 'auto'})")
|
|||
|
|
time.sleep(0.8)
|
|||
|
|
|
|||
|
|
# 3. 点击打招呼(先在该人所在卡片内找)
|
|||
|
|
parent = name_ele.parent()
|
|||
|
|
greet_btn = None
|
|||
|
|
for _ in range(8):
|
|||
|
|
if not parent:
|
|||
|
|
break
|
|||
|
|
greet_btn = parent.ele('x://span[text()="打招呼"]', timeout=0.5) or parent.ele('x://*[contains(text(),"打招呼")]', timeout=0.5)
|
|||
|
|
if greet_btn:
|
|||
|
|
break
|
|||
|
|
parent = parent.parent()
|
|||
|
|
if not greet_btn:
|
|||
|
|
greet_btn = container.ele('x://span[text()="打招呼"]', timeout=2) or container.ele('x://*[contains(text(),"打招呼")]', timeout=1)
|
|||
|
|
if not greet_btn:
|
|||
|
|
raise Exception("未找到「打招呼」按钮")
|
|||
|
|
greet_btn.click(by_js=True)
|
|||
|
|
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
import sys
|
|||
|
|
from pathlib import Path
|
|||
|
|
_root = Path(__file__).resolve().parent
|
|||
|
|
if str(_root) not in sys.path:
|
|||
|
|
sys.path.insert(0, str(_root))
|
|||
|
|
from worker.bit_browser import BitBrowserAPI
|
|||
|
|
from DrissionPage import ChromiumPage, ChromiumOptions
|
|||
|
|
|
|||
|
|
bit_api = BitBrowserAPI("http://127.0.0.1:54345")
|
|||
|
|
cdp_addr, port, browser_id = bit_api.open_browser(browser_id=None, name="测试2", remark=None)
|
|||
|
|
page = ChromiumPage(addr_or_opts=ChromiumOptions().set_local_port(port=port))
|
|||
|
|
page.get("https://www.zhipin.com/web/geek/recommend")
|
|||
|
|
time.sleep(2)
|
|||
|
|
do_greet(page, 姓名)
|