|
| 1 | +from typing import Union |
| 2 | + |
| 3 | +from python3_capsolver.core.base import BaseCaptcha |
| 4 | +from python3_capsolver.core.enum import BinanceCaptchaTaskEnm |
| 5 | +from python3_capsolver.core.serializer import CaptchaResponseSer, BinanceCaptchaTaskSer |
| 6 | + |
| 7 | + |
| 8 | +class Binance(BaseCaptcha): |
| 9 | + """ |
| 10 | + The class is used to work with Capsolver Imperva method. |
| 11 | +
|
| 12 | + Args: |
| 13 | + api_key: Capsolver API key |
| 14 | + captcha_type: Captcha type name, like ``AntiImpervaTask`` and etc. |
| 15 | + websiteUrl: The website url |
| 16 | + userAgent: Browser userAgent |
| 17 | +
|
| 18 | + Examples: |
| 19 | + >>> Binance(api_key="CAI-BA9XXXXXXXXXXXXX2702E010", |
| 20 | + ... captcha_type="BinanceCaptchaTask", |
| 21 | + ... websiteURL="https://www.milanuncios.com/", |
| 22 | + ... websiteKey="login", |
| 23 | + ... validateId="3621a4fef82f4ab4a00e8b07465761c5", |
| 24 | + ... ).captcha_handler() |
| 25 | + CaptchaResponseSer(errorId=0, |
| 26 | + errorCode=None, |
| 27 | + errorDescription=None, |
| 28 | + taskId='73bdcd28-6c77-4414-8....', |
| 29 | + status=<ResponseStatusEnm.Ready: 'ready'>, |
| 30 | + solution={'token': '90F9EAF...'} |
| 31 | + ) |
| 32 | +
|
| 33 | + >>> Binance(api_key="CAI-BA9XXXXXXXXXXXXX2702E010", |
| 34 | + ... captcha_type=BinanceCaptchaTaskEnm.BinanceCaptchaTask, |
| 35 | + ... websiteURL="https://www.milanuncios.com/", |
| 36 | + ... websiteKey="login", |
| 37 | + ... validateId="3621a4fef82f4ab4a00e8b07465761c5", |
| 38 | + ... ).captcha_handler() |
| 39 | + CaptchaResponseSer(errorId=0, |
| 40 | + errorCode=None, |
| 41 | + errorDescription=None, |
| 42 | + taskId='73bdcd28-6c77-4414-8....', |
| 43 | + status=<ResponseStatusEnm.Ready: 'ready'>, |
| 44 | + solution={'token': '90F9EAF...'} |
| 45 | + ) |
| 46 | +
|
| 47 | + >>> await Binance(api_key="CAI-BA9650D2B9C2786B21120D512702E010", |
| 48 | + ... captcha_type=BinanceCaptchaTaskEnm.BinanceCaptchaTask, |
| 49 | + ... websiteURL="https://www.milanuncios.com/", |
| 50 | + ... websiteKey="login", |
| 51 | + ... validateId="3621a4fef82f4ab4a00e8b07465761c5", |
| 52 | + ... ).aio_captcha_handler() |
| 53 | + CaptchaResponseSer(errorId=0, |
| 54 | + errorCode=None, |
| 55 | + errorDescription=None, |
| 56 | + taskId='73bdcd28-6c77-4414-8....', |
| 57 | + status=<ResponseStatusEnm.Ready: 'ready'>, |
| 58 | + solution={'token': '90F9EAF...'} |
| 59 | + ) |
| 60 | +
|
| 61 | + Returns: |
| 62 | + CaptchaResponseSer model with full server response |
| 63 | +
|
| 64 | + Notes: |
| 65 | + https://docs.capsolver.com/guide/captcha/BnCaptcha.html |
| 66 | + """ |
| 67 | + |
| 68 | + def __init__( |
| 69 | + self, |
| 70 | + captcha_type: Union[BinanceCaptchaTaskEnm, str], |
| 71 | + websiteURL: str, |
| 72 | + validateId: str, |
| 73 | + websiteKey: str = "login", |
| 74 | + *args, |
| 75 | + **kwargs, |
| 76 | + ): |
| 77 | + super().__init__(*args, **kwargs) |
| 78 | + |
| 79 | + if captcha_type == BinanceCaptchaTaskEnm.BinanceCaptchaTask: |
| 80 | + self.task_params = BinanceCaptchaTaskSer(**locals()).dict() |
| 81 | + else: |
| 82 | + raise ValueError( |
| 83 | + f"""Invalid `captcha_type` parameter set for `{self.__class__.__name__}`, |
| 84 | + available - {BinanceCaptchaTaskEnm.list_values()}""" |
| 85 | + ) |
| 86 | + |
| 87 | + for key in kwargs: |
| 88 | + self.task_params.update({key: kwargs[key]}) |
| 89 | + |
| 90 | + def captcha_handler(self) -> CaptchaResponseSer: |
| 91 | + """ |
| 92 | + Sync solving method |
| 93 | +
|
| 94 | + Returns: |
| 95 | + CaptchaResponseSer model with full service response |
| 96 | +
|
| 97 | + Notes: |
| 98 | + Check class docstring for more info |
| 99 | + """ |
| 100 | + return self._processing_captcha(create_params=self.task_params) |
| 101 | + |
| 102 | + async def aio_captcha_handler(self) -> CaptchaResponseSer: |
| 103 | + """ |
| 104 | + Async method for captcha solving |
| 105 | +
|
| 106 | + Returns: |
| 107 | + CaptchaResponseSer model with full service response |
| 108 | +
|
| 109 | + Notes: |
| 110 | + Check class docstring for more info |
| 111 | + """ |
| 112 | + return await self._aio_processing_captcha(create_params=self.task_params) |
0 commit comments