自学内容网 自学内容网

【Python selenium过极验滑块】用自动化selenium 操作GEETEST极验滑块,简单粗暴

文章日期:2024.07.24

使用工具:Python

文章类型:自动化过极验滑块

文章全程已做去敏处理!!!  【需要做的可联系我】 

AES解密处理(直接解密即可)(crypto-js.js 标准算法):​​​​​​在线AES加解密工具

【点赞 收藏 关注 】仅供学习,仅供学习。

注意:要用Google浏览器和Google驱动,可以在这里下载Google浏览器 和 浏览器驱动下载 教程分享
今天用Python 的 selenium模块,自动化过极验滑块验证,很好用哦

先看效果,觉得效果不好就滑走吧

看完了吗,代码拿走吧,注释写的很明白,不懂可以留言哦
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import time
import re
import requests
# 安装库 pip install ddddocr
import ddddocr
# 运行脚本实列化一次即可,不要重复实列化,会浪费时间
det = ddddocr.DdddOcr(det=False, ocr=False)

# 配置 Chrome 浏览器
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = "chrome/chrome.exe"  # 指定 Chrome 浏览器的路径
chrome_options.add_argument("--disable-infobars")   #  禁用浏览器中的"信息栏",避免干扰测试。
# 启动浏览器
driver = webdriver.Chrome(options=chrome_options)

# 打开 Google
driver.get("http://gt4.geetest.com/")

print('点击开始验证')
# 点击验证
driver.find_element(By.XPATH,r'/html/body/div/div/div[2]/div[2]/form/div[3]/div[3]/div[1]/div[1]').click()
print('等待加载')
time.sleep(4)
data = driver.page_source
# 背景图
beijnigtu = re.findall('class="geetest_bg_.*?url\("(.*?)"\);',data)
# 小拼图
xiaopintu = re.findall('class="geetest_slice_bg_.*?url\("(.*?)"\);',data)
print('成功获取背景图和小拼图的链接')
# 请求背景图
requests_beijnigtu = requests.get(beijnigtu[0]).content
# 小拼图
requests_xiaopintu = requests.get(xiaopintu[0]).content
print('背景图和小拼图已请求成功!!!')
# 开始识别滑块距离
res1 = det.slide_match(requests_beijnigtu, requests_xiaopintu, simple_target=True)['target'][0]
print(f'识别出距离:{res1}')
# 定位滑块的滑动按钮
element = driver.find_element(By.XPATH,r'/html/body/div/div/div[2]/div[2]/form/div[3]/div[3]/div[1]/div[4]/div[1]/div[2]/div/div/div[2]/div/div[3]')
print('滑动按钮已定位')
# 点击并抓住标签
ActionChains(driver).click_and_hold(element).perform()
print('开始滑动')
# 开始滑动
ActionChains(driver).move_by_offset(xoffset=res1-1, yoffset=0).perform()  # 向右滑动114像素(向左是负数)
# 松开按钮
ActionChains(driver).release().perform()
print('完成')
print('等待执行其他操作!!!')
time.sleep(1000)
# 关闭浏览器
driver.quit()

原文地址:https://blog.csdn.net/weixin_46625757/article/details/140673113

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!