某验五子棋验证码

测试地址

aHR0cHM6Ly9ndDQuZ2VldGVzdC5jb20=

python代码

#!/usr/bin/python
# -*- coding: UTF-8 -*-    
# Author:Jruing
# FileName:极验证码v4五子棋
# DateTime:2021/10/14 15:08
# SoftWare: PyCharm


from lxml.html import etree
import re
import copy

# from selenium.webdriver import Chrome
# from selenium.webdriver.common.action_chains import ActionChains
#
# import time
#
# driver = Chrome(executable_path=r'D:\tools\chromedriver.exe')
# driver.get("https://gt4.geetest.com/")
# driver.maximize_window()
# time.sleep(10)
# input("ssss")
# print(driver.page_source)
# html = etree.HTML(driver.page_source)

page_source = """
<div class="geetest_wrap"><div class="geetest_result_tips"></div><div class="geetest_subitem geetest_winlinze"><div class="geetest_item-0 geetest_item"><div class="geetest_item-0-0-bg geetest_itembg" style="left: 3%; top: 4%;"></div><div class="geetest_item-0-0 geetest_itemimg geetest_isEmpty" style="left: 3%; top: 4%;"></div><div class="geetest_item-0-1-bg geetest_itembg" style="left: 23%; top: 4%;"></div><div class="geetest_item-0-1 geetest_itemimg geetest_isEmpty" style="left: 23%; top: 4%;"></div><div class="geetest_item-0-2-bg geetest_itembg" style="left: 43%; top: 4%;"></div><div class="geetest_item-0-2 geetest_itemimg geetest_isEmpty" style="left: 43%; top: 4%;"></div><div class="geetest_item-0-3-bg geetest_itembg" style="left: 63%; top: 4%;"></div><div class="geetest_item-0-3 geetest_itemimg geetest_isEmpty" style="left: 63%; top: 4%;"></div><div class="geetest_item-0-4-bg geetest_itembg" style="left: 83%; top: 4%;"></div><div class="geetest_item-0-4 geetest_itemimg geetest_isEmpty" style="left: 83%; top: 4%;"></div></div><div class="geetest_item-1 geetest_item"><div class="geetest_item-1-0-bg geetest_itembg" style="left: 3%; top: 23%;"></div><div class="geetest_item-1-0 geetest_itemimg geetest_isEmpty" style="left: 3%; top: 23%;"></div><div class="geetest_item-1-1-bg geetest_itembg" style="left: 23%; top: 23%;"></div><div class="geetest_item-1-1 geetest_itemimg geetest_isEmpty" style="left: 23%; top: 23%;"></div><div class="geetest_item-1-2-bg geetest_itembg" style="left: 43%; top: 23%;"></div><div class="geetest_item-1-2 geetest_itemimg geetest_isEmpty" style="left: 43%; top: 23%;"></div><div class="geetest_item-1-3-bg geetest_itembg" style="left: 63%; top: 23%;"></div><div class="geetest_item-1-3 geetest_itemimg" style="background-image: url(&quot;https://static.geetest.com/nerualpic/v4_test/v4_winlinze_test/img_winlinze_2.png&quot;); left: 63%; top: 23%;"></div><div class="geetest_item-1-4-bg geetest_itembg" style="left: 83%; top: 23%;"></div><div class="geetest_item-1-4 geetest_itemimg geetest_isEmpty" style="left: 83%; top: 23%;"></div></div><div class="geetest_item-2 geetest_item"><div class="geetest_item-2-0-bg geetest_itembg" style="left: 3%; top: 42%;"></div><div class="geetest_item-2-0 geetest_itemimg geetest_isEmpty" style="left: 3%; top: 42%;"></div><div class="geetest_item-2-1-bg geetest_itembg" style="left: 23%; top: 42%;"></div><div class="geetest_item-2-1 geetest_itemimg geetest_isEmpty" style="left: 23%; top: 42%;"></div><div class="geetest_item-2-2-bg geetest_itembg" style="left: 43%; top: 42%;"></div><div class="geetest_item-2-2 geetest_itemimg" style="background-image: url(&quot;https://static.geetest.com/nerualpic/v4_test/v4_winlinze_test/img_winlinze_2.png&quot;); left: 43%; top: 42%;"></div><div class="geetest_item-2-3-bg geetest_itembg" style="left: 63%; top: 42%;"></div><div class="geetest_item-2-3 geetest_itemimg geetest_isEmpty" style="left: 63%; top: 42%;"></div><div class="geetest_item-2-4-bg geetest_itembg" style="left: 83%; top: 42%;"></div><div class="geetest_item-2-4 geetest_itemimg geetest_isEmpty" style="left: 83%; top: 42%;"></div></div><div class="geetest_item-3 geetest_item"><div class="geetest_item-3-0-bg geetest_itembg" style="left: 3%; top: 61%;"></div><div class="geetest_item-3-0 geetest_itemimg" style="background-image: url(&quot;https://static.geetest.com/nerualpic/v4_test/v4_winlinze_test/img_winlinze_2.png&quot;); left: 3%; top: 61%;"></div><div class="geetest_item-3-1-bg geetest_itembg" style="left: 23%; top: 61%;"></div><div class="geetest_item-3-1 geetest_itemimg" style="background-image: url(&quot;https://static.geetest.com/nerualpic/v4_test/v4_winlinze_test/img_winlinze_2.png&quot;); left: 23%; top: 61%;"></div><div class="geetest_item-3-2-bg geetest_itembg" style="left: 43%; top: 61%;"></div><div class="geetest_item-3-2 geetest_itemimg geetest_isEmpty" style="left: 43%; top: 61%;"></div><div class="geetest_item-3-3-bg geetest_itembg" style="left: 63%; top: 61%;"></div><div class="geetest_item-3-3 geetest_itemimg geetest_isEmpty" style="left: 63%; top: 61%;"></div><div class="geetest_item-3-4-bg geetest_itembg" style="left: 83%; top: 61%;"></div><div class="geetest_item-3-4 geetest_itemimg geetest_isEmpty" style="left: 83%; top: 61%;"></div></div><div class="geetest_item-4 geetest_item"><div class="geetest_item-4-0-bg geetest_itembg" style="left: 3%; top: 80%;"></div><div class="geetest_item-4-0 geetest_itemimg" style="background-image: url(&quot;https://static.geetest.com/nerualpic/v4_test/v4_winlinze_test/img_winlinze_2.png&quot;); left: 3%; top: 80%;"></div><div class="geetest_item-4-1-bg geetest_itembg" style="left: 23%; top: 80%;"></div><div class="geetest_item-4-1 geetest_itemimg geetest_isEmpty" style="left: 23%; top: 80%;"></div><div class="geetest_item-4-2-bg geetest_itembg" style="left: 43%; top: 80%;"></div><div class="geetest_item-4-2 geetest_itemimg geetest_isEmpty" style="left: 43%; top: 80%;"></div><div class="geetest_item-4-3-bg geetest_itembg" style="left: 63%; top: 80%;"></div><div class="geetest_item-4-3 geetest_itemimg geetest_isEmpty" style="left: 63%; top: 80%;"></div><div class="geetest_item-4-4-bg geetest_itembg" style="left: 83%; top: 80%;"></div><div class="geetest_item-4-4 geetest_itemimg geetest_isEmpty" style="left: 83%; top: 80%;"></div></div></div></div>


"""
html = etree.HTML(page_source)
class_list = html.xpath('//div[@class="geetest_subitem geetest_winlinze"]/div/div/@class')
class_lists = [[class_list[j], class_list[j + 1]] for j in range(0, len(class_list), 2)]

"""
0 空
1 蓝
2 黄
3 白
4 黑
"""
rs = []
for i in range(0, 5):
    rs.append(class_lists[i * 5:(i + 1) * 5])
for index, i in enumerate(rs):
    for j in i:
        colors = html.xpath(f"""//div/div/div[@class="{j[1]}"]/@style""")[0]
        if "url" in colors:
            colors = re.compile('url\("https://static.geetest.com/.*?img_winlinze_(\d+).png"\)', re.S).findall(colors)[
                0]
        else:
            colors = '0'
        j.clear()
        j.append(colors)

rs_list = [[k[0] for k in i] for i in rs]
width = 60
high = 50
center = 30


def check_rows():
    rs = copy.deepcopy(rs_list)
    # 获取符合条件的行
    target_x, target_y, check_x, check_y = 0, 0, 0, 0
    flag = -1
    for rows in rs:
        if rows.count('0') == 1 and len(set(rows)) == 2:
            target_y = rows.index('0')+1
            target_x = rs.index(rows)+1
            # 获取应该放在该位置棋子的颜色代码
            rows.remove('0')
            flag = rows[0]
            row_num = rs.index(rows)
            rs[row_num]=[]
            break
    if flag != -1:
        for i in rs:
            if flag in i:
                print(i.index(flag),rs.index(i))
                check_y = i.index(flag)+1
                check_x = rs.index(i)+1
                break
    return target_x, target_y, check_x, check_y


def check_columns():
    # 按照列
    rs = copy.deepcopy(rs_list)
    target_x, target_y, check_x, check_y = 0, 0, 0, 0
    flag = -1
    for columns in range(0, 5):
        rs_columns = [col[columns] for col in rs]
        if rs_columns.count('0') == 1 and len(set(rs_columns)) == 2:
            target_x = rs_columns.index('0')+1
            target_y = columns+1
            # 获取应该放在该位置棋子的颜色代码
            rs_columns.remove('0')
            flag = rs_columns[0]
            break
    if flag != -1:
        for i in rs:
            row_num = rs.index(i)
            rs[row_num][target_y-1]=-2
            if flag in i:
                check_y = i.index(flag)+1
                check_x = rs.index(i)+1
                break
    return target_x, target_y, check_x, check_y


def slash_right():
    # \ 斜着
    rs = copy.deepcopy(rs_list)

    flag = -1
    target_x, target_y, check_x, check_y = 0, 0, 0, 0

    right = [rs[i][i] for i in range(0, 5)]
    if right.count('0') == 1 and len(set(right)) == 2:
        target_x = right.index('0')+1
        target_y = right.index('0')+1
        right.remove('0')
        flag = right[0]
    for index, item in enumerate(rs):
        rs[index][index] = -2
        if flag in item:
            check_x = index+1
            check_y = item.index(flag)+1
            break
    return target_x, target_y, check_x, check_y


def slash_left():
    # / 斜着
    rs = copy.deepcopy(rs_list)
    flag = -1
    target_x, target_y, check_x, check_y = 0, 0, 0, 0
    left = [rs[i][-1 - i] for i in range(0, 5)]
    if left.count('0') == 1 and len(set(left)) == 2:
        target_x = left.index('0')+1
        target_y = 5-left.index('0')
        left.remove('0')
        flag = left[0]

    for index, item in enumerate(rs):
        rs[index][-1 - index] = -2
        if flag in item:
            check_x = index+1
            check_y = item.index(flag)+1
            break
    return target_x, target_y, check_x, check_y


target_x, target_y, check_x, check_y = check_rows()
if target_x == target_y == check_x == check_y:
    print("未发现符合规则的行")
else:
    print(f"行: 棋子{check_x}:{check_y} 移动到{target_x}:{target_y}")

target_x, target_y, check_x, check_y = check_columns()
if target_x == target_y == check_x == check_y:
    print("未发现符合规则的列")
else:
    print(f"列: 棋子{check_x}:{check_y} 移动到{target_x}:{target_y}")

target_x, target_y, check_x, check_y = slash_right()
if target_x == target_y == check_x == check_y:
    print("未发现符合规则的对角(\)")
else:
    print(f"\: 棋子{check_x}:{check_y} 移动到{target_x}:{target_y}")

target_x, target_y, check_x, check_y = slash_left()
if target_x == target_y == check_x == check_y:
    print("未发现符合规则的对角(/)")
else:
    print(f"/: 棋子{check_x}:{check_y} 移动到{target_x}:{target_y}")

# ActionChains(driver).move_by_offset(x - 30 + 1060, y - 30).click().perform()  # 鼠标左键点击, 200为x坐标, 100为y坐标

上一篇:微软应用商店现“克隆”游戏,内涵恶意程序Electron Bot


下一篇:u-boot driver_check_compatible函数