使用的是 selenium4的 和3的版本语法有点出入 但是大差不差 暂时还没有完善 会持续更新
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
option = webdriver.ChromeOptions()
option.add_experimental_option("detach", True)
# 获取driver对象, 并将配置好的option传入进去 运行结束不关闭窗口
driver = webdriver.Chrome(options=option)
driver.get("https://www.zhipin.com/shenzhen/?sid=sem_pz_bdpc_dasou_title")
time.sleep(2)
#点击注册登陆
# driver.find_element(".user-nav .btns .btn-outline").click()
login = driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div[1]/div[4]/div/a').click()
bossType = input("手机号登录请输入1 微信登录请输入2:")
if bossType.isdigit():
if bossType=='1':
#输入登陆的手机号
phone = input("请输入手机号")
driver.find_element(By.XPATH,"./html/body/div/div/div[2]/div[2]/div[2]/div[1]/div[1]/div/span[2]/input").send_keys(phone)
#获取验证码
driver.find_element(By.XPATH,"/html/body/div/div/div[2]/div[2]/div[2]/div[1]/div[2]/div/span/div").click()
time.sleep(5)
# #点击完成验证
driver.find_element(By.XPATH,"/html/body/div/div/div[2]/div/div[2]/div[1]/div[2]/div/span/div").click()
time.sleep(3)
#输入验证码
yzm = input("请输入验证码")
#输入验证码
driver.find_element(By.XPATH,"/html/body/div/div/div[2]/div/div[2]/div[1]/div[2]/div/span/input").send_keys(yzm)
#点击登协议 .login-policy-wrapper > .agree-policy-wrapper
driver.find_element(By.XPATH,"/html/body/div/div/div[2]/div[2]/div[2]/div[2]/span/input").click()
#点击登陆
driver.find_element(By.XPATH,"/html/body/div/div/div[2]/div[2]/div[2]/div[1]/div[3]/button").click()
time.sleep(10)
elif bossType=='2':
driver.find_element(By.XPATH,"/html/body/div/div/div[2]/div[2]/div[2]/div[1]/div[4]/a").click()
time.sleep(10)
else:
print("傻逼 中文都看不懂 输入数字,还用个屁软件 滚啊")
# 等待登录后的页面加载完成
print(driver.current_url)
# time.sleep(10)
# title_contains 网页标题是否包含特定内容,如果是返回True,否则返回False 显示等待
WebDriverWait(driver, 10).until(EC.title_contains("BOSS直聘"))
# 等待重定向,通常是检查页面标题或其他特定元素的出现
# WebDriverWait(driver, 10).until(EC.title_is("BOSS直聘"))
# print (driver.title)
# 或者使用其他条件,例如EC.presence_of_element_located((By.ID, "some_element_on_redirected_page"))
# 打印当前路径
# 尝试直接跳转
# driver.get("https://www.zhipin.com/shenzhen/?sid=sem_pz_bdpc_dasou_title")
# 判断元素是否存在
handles = driver.window_handles #获取当前浏览器的所有窗口句柄
driver.switch_to.window(handles[-1])
driver.get("https://www.zhipin.com/web/geek/job-recommend")
# test_element = driver.find_element(By.XPATH,"/html/body/div[1]/div[1]/div/div/div[1]")
try:
time.sleep(2)
driver.window_handles
test_element = driver.find_element(By.XPATH,"/html/body/div[1]/div[1]/div/div/div[1]")
print("判断元素是否存在")
except:
print('异常说明')
标签:body,python,driver,boss,element,html,div,投递,find
From: https://blog.csdn.net/weixin_43686599/article/details/136971737