python滑块验证(打码)+pillow裁剪图片

用的图鉴的接口

缺口图+背景图的接口识别很准,但要传2张图

背景图带滑块,需要裁调滑块部分

# x,y:426x248
from PIL import Image  as  image
img = image.open("D:\lpt_img\\img_bgk.png")
# 按缩放比例 算出要裁剪的距离左边的x值
x_1=int(27/(340/426))
x=x_1+85
cropped = img.crop((x,0,426,248)) # (left, upper, right, lower)
cropped.save("D:\lpt_img\\img_bgk1.png")

在这里插入图片描述
在这里插入图片描述
调接口取x轴位移数

import json
import requests
import base64
from io import BytesIO
from PIL import Image  as image
from sys import version_info


def get_x(uname, pwd, img_bgk):
    #
    # img = img.convert('RGB')
    img_bgk = img_bgk.convert('RGB')
    # buffered_img = BytesIO()
    # img.save(buffered_img, format="JPEG")
    buffered_img_bgk = BytesIO()
    img_bgk.save(buffered_img_bgk, format("JPEG"))
    # if version_info.major >= 3:
    #     b64_img = str(base64.b64encode(buffered_img.getvalue()), encoding='utf-8')
    # else:
    #     b64_img = str(base64.b64encode(buffered_img.getvalue()))
    if version_info.major >= 3:
        b64_img_bgk = str(base64.b64encode(buffered_img_bgk.getvalue()), encoding='utf-8')
    else:
        b64_img_bgk = str(base64.b64encode(buffered_img_bgk.getvalue()))

    data = {"username": uname, "password": pwd, "image": b64_img_bgk, "typeid": 33}
    result = json.loads(requests.post("http://api.ttshitu.com/base64", json=data).text)
    if result['success']:
        return result["data"]["result"]
    else:
        return result["message"]
    return ""


def get_img(img_bgk_path):
    # img = image.open(img_path)
    # 裁剪bgk_img
    img_bgk1 = image.open(img_bgk_path)
    # 按缩放比例 算出要裁剪的距离左边的x值
    x_1 = int(27 / (340 / 426))
    # 
    x = x_1 + 85
    img_bgk = img_bgk1.crop((x, 0, 426, 248))  # (left, upper, right, lower)
    # img_bgk=image.open(img_bgk)
    # return img,img_bgk
    return img_bgk


if __name__ == "__main__":
    # img_path = "D:\\lpt_img\\img.png"
    img_bgk_path = "D:\lpt_img\\img_bgk.png"
    # img,img_bgk=get_img(img_path,img_bgk_path)
    img_bgk = get_img(img_bgk_path)
    # print(img,img_bgk)
    result = get_x(uname='', pwd='', img_bgk=img_bgk)
    # print(result)
    # move_x=int(result.split(",")[0])

    # x轴位移量
    x = int((int(result) + 85) * (340 / 426))
    print(x)   # 221

测试位移量(多测几遍 误差不大就行了)

起始值+位移值=缺口值
在这里插入图片描述
后边就用selenium拖动滑块

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值