开箱即用python破解滑块缺口验证码

该代码实现了一个从网页获取验证码,处理图像以定位白色像素,然后进行移动并发送请求的过程。主要用于网页数据的抓取,涉及到图像处理、HTTP请求和Cookie管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    def get_position( datu):
        i_j = []
        img = Image.open(io.BytesIO(datu))
        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
 	def get_sectoken( 1):
        for retry_num in range(3):
            try:
                time.sleep(0.1)
                headers = {
                    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.33',
                }
                yzm_url = 'https://gcxm.hunanjs.gov.cn/AjaxHandler/PersonHandler.ashx?method=GetVerifyImg'
                yzm_res = requests.get(yzm_url, proxies=self.proxies, timeout=15, headers=headers)
                vid = yzm_res.json()[2]
                datu = base64.b64decode(yzm_res.json()[1])
                move_x = int(get_position(datu)[0][0])
                headers['Cookie'] = f'ASP.NET_SessionId={yzm_res.cookies.get("ASP.NET_SessionId")}'
                for x in [-1, -2, -3, 0, -5, -2, -1, 0]:
                    time.sleep(0.1)
                    move_x_v2 = move_x + x
                    url = f'https://gcxm.hunanjs.gov.cn/AjaxHandler/PersonHandler.ashx?method=GetListPage&type=6&corptype_1=&corpname_1=&licensenum_1=&Province_1=430000&City_1=&county_1=&persontype=&persontype_2=&personname_2=&idcard_2=&certnum_2=&corpname_2=&prjname_3=&corpname_3=&prjtype_3=&cityname_3=&corpname_5=&corpcode_5=&legalman_5=&cityname_5=&SafeNum_6=&corpname_6=&corpname_7=&piciname_7=&corptype_7=&corpname_8=&corpcode_8=&legalman_8=&cityname_8=&pageSize=30&pageIndex={page}&moveX={move_x_v2}&verifyid={vid}'
                    res = requests.get(url, proxies=self.proxies, headers=headers, timeout=15)
                    if '图片验证失败' in res.text:
                        continue
                    return res.json().get('data')
            except Exception as e:
                logging.info(e)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值