【Python selenium过极验五子棋】自动化过五子棋人机验证,享受丝滑的落子,秒了

文章日期:2024.07.25

使用工具:Python

文章类型:自动化过极验五子棋

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

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

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

今天用Python 的 selenium模块,自动化过极验五子棋,先看视频
这个是手动验证的,需要输入指定数字才能开始验证,是一个while死循环,是为了方便展示
1、五子棋人机验证比上一次的哪个消消乐还要简单,哪个消消乐的图片的url全部都不一样,这个五子棋的图片的url都是一样的,又节约了时间和流量
2、这次的人机验证也没什么难度,看图说话

3、难度不大,也没什么好讲的,有些注释没写是因为屎山不需要注释,其次是因为我写代码时都是突然来的灵感,没来的及写,等回过头就忘了要写什么注释了,干脆就不写了,总之我都会,你们不会的可以自己研究一下,还不会就留言,等我给你慢慢讲

【附上代码】教程可能不是很清晰明了,有不懂可以留言或私信

python 复制代码
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import re
import hashlib

def md5_encrypt(string):
    md5 = hashlib.md5()
    md5.update(string.encode('utf-8'))
    return md5.hexdigest()
# 配置 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('点击开始验证')
time.sleep(0.5)
# 点击配置
driver.find_element(By.XPATH, r'/html/body/div/div/div[4]/div[1]').click()
time.sleep(0.5)
# 点击五子棋验证
driver.find_element(By.XPATH, r'/html/body/div/div/div[4]/div[2]/div[2]/div[1]/div[2]/div[3]/div[6]').click()
time.sleep(0.5)
# 点击验证按钮
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('等待加载')

data = driver.page_source
# 字典格式的数据
list_chart1 = []
# 数据转哈希
list_chart2 = []
# 上下
for _y in range(5):
    # 左右
    for _x in range(5):
        if re.findall(f'geetest_item-{_y}-{_x} geetest_itemimg geetest_isEmpty', data):
            chart_url = ''
        else:
            chart_url = md5_encrypt(re.findall(f'geetest_item-{_y}-{_x}_.*?url\("(.*?)"\)', data)[0])
        list_chart1 += [{f'{_y+1}-{_x+1}': chart_url}]
        list_chart2 += [chart_url]
print(f'五子棋已排列完成:{list_chart1}')
# 去重
quchong = []
# 要查找的参数
chuang = ''
# 目标棋子 & 重点坐标
target = ['','']
print('开始检测五子棋并查找缺口!!!')
if list_chart2[4::4][:-1].count('') == 1 and len(set(list_chart2[4::4][:-1])) == 2:
    quchong += ['1-5','2-4','3-3','4-2','5-1']
    chuang = list(filter(None, set(list_chart2[4::4][:-1])))[0]
    target[1] = f'{list_chart2[4::4][:-1].index("")+1}-{6-(list_chart2[4::4][:-1].index("")+1)}'
if list_chart2[::6].count('') == 1 and len(set(list_chart2[::6])) == 2:
    quchong += ['1-1','2-2','3-3','4-4','5-5']
    chuang = list(filter(None, set(list_chart2[::6])))[0]
    target[1] = f'{list_chart2[::6].index("")+1}-{list_chart2[::6].index("")+1}'
for number in range(5):
    number_1 = number * 5
    if list_chart2[number_1:number_1+5].count('') == 1 and len(set(list_chart2[number_1:number_1+5])) == 2:
        quchong += [f'{number_1 // 5 + 1}-{a+1}' for a in range(5)]
        chuang = list(filter(None, set(list_chart2[number_1:number_1+5])))[0]
        target[1] = list(list_chart1[number_1+list_chart2[number_1:number_1+5].index('')].keys())[0]
    if list_chart2[number::5].count('') == 1 and len(set(list_chart2[number::5])) == 2:
        quchong += [f'{a+1}-{number+1}' for a in range(5)]
        chuang = list(filter(None,set(list_chart2[number::5])))[0]
        target[1] = list(list_chart1[number+list_chart2[number::5].index('')*5].keys())[0]
    if quchong:
        for _ in list_chart1:
            if list(_.keys())[0] not in quchong and list(_.values())[0] == chuang:
                target[0] = list(_.keys())[0]
        break
print(f'缺口方位:{target[0]} 目标棋子方位:{target[1]}')
print('准备移动 - 略等2秒,怕页面没加载出来!!!')
# 此处要加间隔时间,防止图片没有加载出来
time.sleep(2)
driver.find_element(By.XPATH,
                    rf'/html/body/div/div/div[2]/div[2]/form/div[3]/div[3]/div[1]/div[4]/div[1]/div[2]/div/div[2]/div[{target[0].split("-")[0]}]/div[{int(target[0].split("-")[1])*2}]').click()
time.sleep(0.1)
driver.find_element(By.XPATH,
                    rf'/html/body/div/div/div[2]/div[2]/form/div[3]/div[3]/div[1]/div[4]/div[1]/div[2]/div/div[2]/div[{target[1].split("-")[0]}]/div[{int(target[1].split("-")[1])*2}]').click()
print('验证成功!!!')

print('等待执行其他操作!!!\n\n')

time.sleep(10000)
# 关闭浏览器
driver.quit()
相关推荐
历程里程碑1 小时前
普通数组----合并区间
java·数据结构·python·算法·leetcode·职场和发展·tornado
weixin_395448911 小时前
mult_yolov5_post_copy.c_cursor_0205
c语言·python·yolo
执风挽^1 小时前
Python基础编程题2
开发语言·python·算法·visual studio code
纤纡.1 小时前
PyTorch 入门精讲:从框架选择到 MNIST 手写数字识别实战
人工智能·pytorch·python
kjkdd2 小时前
6.1 核心组件(Agent)
python·ai·语言模型·langchain·ai编程
小镇敲码人2 小时前
剖析CANN框架中Samples仓库:从示例到实战的AI开发指南
c++·人工智能·python·华为·acl·cann
萧鼎2 小时前
Python 包管理的“超音速”革命:全面上手 uv 工具链
开发语言·python·uv
alvin_20052 小时前
python之OpenGL应用(二)Hello Triangle
python·opengl
铁蛋AI编程实战3 小时前
通义千问 3.5 Turbo GGUF 量化版本地部署教程:4G 显存即可运行,数据永不泄露
java·人工智能·python
jiang_changsheng3 小时前
RTX 2080 Ti魔改22GB显卡的最优解ComfyUI教程
python·comfyui