selenium过滑块验证码自动注册账号

本文介绍如何利用Python的Selenium库自动化处理滑块验证码,实现账号的自动注册。详细步骤见GitHub项目的相关说明。
摘要由CSDN通过智能技术生成
import io
import json
import os
import random
import time
import traceback
from threading import Thread

import func_timeout
import requests
import selenium
from PIL import Image
from func_timeout import func_set_timeout
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager


def login(email, passwd):
    url = 'https://v2.freeyes.xyz/auth/login'
    data = {
   'email': email, 'passwd': passwd}
    headers = {
   'user-agent': None}
    try:
        r = requests.post(url, data=data, headers=headers, timeout=10)
    except requests.exceptions.ReadTimeout:
        pass
    try:
        if r.json()['ret'] == 0:
            return
    except json.decoder.JSONDecodeError:
        return
    cookies = r.cookies.get_dict()
    print(cookies)
    return cookies


class register:
    __species = None
    chrome = None

    def __new__(cls, *args, **kwargs):
        if not cls.__species:
            cls.__species = object.__new__(cls)
            cls.chrome = ChromeDriverManager().install()
        return object.__new__(cls)

    def __init__(self, code=None):
        self.options = webdriver.ChromeOptions()
        self.options.add_argument("--no-sandbox")
        self.options.add_argument("--start-maximized")
        self.__start_crop_image = False
        self.__refresh = False
        self.__success = False
        self.__completed = False
        if not code:
            code = 'eId6'
        self.url = f'https://v2.freeyes.xyz/auth/register?code={code}'
        print(self.url)

    def __del__(self):
        self.__completed = True
        try:
            self.browser.close()
        except (NameError, ImportError, AttributeError, selenium.common.exceptions.InvalidSessionIdException):
            pass
        del self

    def __call__(self):
        try:
            return self.__reg()
        except func_timeout.exceptions.FunctionTimedOut:
            print('运行超时')
            self.__del__()
        except KeyboardInterrupt:
            os._exit(
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值