滑块验证拖动距离

import base64
import json

import requests

headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Cookie': 'ASP.NET_SessionId=dwgdziizfuk4gjxl0rxudunh',
    'Host': 'gcxm.hunanjs.gov.cn',
    'Referer': 'http://gcxm.hunanjs.gov.cn/dataservice.html?queryType=0&keyword=',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest'
}


def get_params(response):
    # print(response.text)
    if not response:
        response = requests.get('http://gcxm.hunanjs.gov.cn/AjaxHandler/PersonHandler.ashx?method=GetVerifyImg',
                                headers=headers)
    data = json.loads(response.text)[1]
    # 2、base64解码
    img = base64.urlsafe_b64decode(data)
    ext = 'png'
    # 3、二进制文件保存
    filename = "{}.{}".format('hunan_bjt', ext)
    with open(filename, "wb") as f:
        f.write(img)
    i_j = find_write(filename)
    i = i_j[0][0]
    code = json.loads(response.text)[2]
    print(i, code)
    return i, code


def find_write(file_name):
    from PIL import Image
    i_j = []
    img = Image.open(file_name)  # 读取照片
    img = img.convert("RGBA")  # 转换格式,确保像素包含alpha通道
    width, height = img.size  # 长度和宽度
    for i in range(0, width):  # 遍历所有长度的点
        for j in range(0, height):  # 遍历所有宽度的点
            data = img.getpixel((i, j))  # 获取一个像素
            if (data.count(255) == 4):  # RGBA都是255,表示白色
                i_j.append((i, j))
    return i_j


if __name__ == '__main__':
    response = requests.get('http://gcxm.hunanjs.gov.cn/AjaxHandler/PersonHandler.ashx?method=GetVerifyImg',
                            headers=headers)
    get_params(response)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值