|
| 1 | +from .core.base import BaseCaptcha |
| 2 | +from .core.enums import CaptchaFoxEnm |
| 3 | + |
| 4 | + |
| 5 | +class CaptchaFox(BaseCaptcha): |
| 6 | + def __init__( |
| 7 | + self, |
| 8 | + websiteURL: str, |
| 9 | + websiteKey: str, |
| 10 | + userAgent: str, |
| 11 | + proxyType: str, |
| 12 | + proxyAddress: str, |
| 13 | + proxyPort: str, |
| 14 | + *args, |
| 15 | + **kwargs, |
| 16 | + ): |
| 17 | + """ |
| 18 | + The class is used to work with CaptchaFox. |
| 19 | +
|
| 20 | + Args: |
| 21 | + rucaptcha_key: User API key |
| 22 | + websiteURL: Full URL of the captcha page |
| 23 | + websiteKey: The value of the `key` parameter. |
| 24 | + It can be found in the page source code or captured in network requests during page loading. |
| 25 | + userAgent: User-Agent of your browser will be used to load the captcha. |
| 26 | + Use only modern browser's User-Agents |
| 27 | + proxyType: Proxy type - `http`, `socks4`, `socks5` |
| 28 | + proxyAddress: Proxy IP address or hostname |
| 29 | + proxyPort: Proxy port |
| 30 | + method: Captcha type |
| 31 | + kwargs: Not required params for task creation request |
| 32 | +
|
| 33 | + Examples: |
| 34 | + >>> CaptchaFox(rucaptcha_key="aa9011f31111181111168611f1151122", |
| 35 | + ... websiteURL="3ceb8624-1970-4e6b-91d5-70317b70b651", |
| 36 | + ... websiteKey="sk_xtNxpk6fCdFbxh1_xJeGflSdCE9tn99G", |
| 37 | + ... userAgent="Mozilla/5.0 .....", |
| 38 | + ... proxyType="socks5", |
| 39 | + ... proxyAddress="1.2.3.4", |
| 40 | + ... proxyPort="445", |
| 41 | + ... ).captcha_handler() |
| 42 | + { |
| 43 | + "errorId":0, |
| 44 | + "status":"ready", |
| 45 | + "solution":{ |
| 46 | + "token":"142000f.....er" |
| 47 | + }, |
| 48 | + "cost":"0.002", |
| 49 | + "ip":"1.2.3.4", |
| 50 | + "createTime":1692863536, |
| 51 | + "endTime":1692863556, |
| 52 | + "solveCount":0, |
| 53 | + "taskId": 73243152973, |
| 54 | + } |
| 55 | +
|
| 56 | + >>> await CaptchaFox(rucaptcha_key="aa9011f31111181111168611f1151122", |
| 57 | + ... websiteURL="3ceb8624-1970-4e6b-91d5-70317b70b651", |
| 58 | + ... websiteKey="sk_xtNxpk6fCdFbxh1_xJeGflSdCE9tn99G", |
| 59 | + ... userAgent="Mozilla/5.0 .....", |
| 60 | + ... proxyType="socks5", |
| 61 | + ... proxyAddress="1.2.3.4", |
| 62 | + ... proxyPort="445", |
| 63 | + ... ).aio_captcha_handler() |
| 64 | + { |
| 65 | + "errorId":0, |
| 66 | + "status":"ready", |
| 67 | + "solution":{ |
| 68 | + "token":"142000f.....er" |
| 69 | + }, |
| 70 | + "cost":"0.002", |
| 71 | + "ip":"1.2.3.4", |
| 72 | + "createTime":1692863536, |
| 73 | + "endTime":1692863556, |
| 74 | + "solveCount":0, |
| 75 | + "taskId": 73243152973, |
| 76 | + } |
| 77 | +
|
| 78 | + Returns: |
| 79 | + Dict with full server response |
| 80 | +
|
| 81 | + Notes: |
| 82 | + https://2captcha.com/api-docs/captchafox |
| 83 | +
|
| 84 | + https://rucaptcha.com/api-docs/captchafox |
| 85 | + """ |
| 86 | + super().__init__(method=CaptchaFoxEnm.CaptchaFoxTask, *args, **kwargs) |
| 87 | + |
| 88 | + self.create_task_payload["task"].update( |
| 89 | + { |
| 90 | + "websiteURL": websiteURL, |
| 91 | + "websiteKey": websiteKey, |
| 92 | + "userAgent": userAgent, |
| 93 | + "proxyType": proxyType, |
| 94 | + "proxyAddress": proxyAddress, |
| 95 | + "proxyPort": proxyPort, |
| 96 | + } |
| 97 | + ) |
| 98 | + |
| 99 | + def captcha_handler(self, **kwargs) -> dict: |
| 100 | + """ |
| 101 | + Sync solving method |
| 102 | +
|
| 103 | + Args: |
| 104 | + kwargs: additional params for `requests` library |
| 105 | +
|
| 106 | + Returns: |
| 107 | + Dict with full server response |
| 108 | +
|
| 109 | + Notes: |
| 110 | + Check class docstirng for more info |
| 111 | + """ |
| 112 | + return self._processing_response(**kwargs) |
| 113 | + |
| 114 | + async def aio_captcha_handler(self) -> dict: |
| 115 | + """ |
| 116 | + Async solving method |
| 117 | +
|
| 118 | + Returns: |
| 119 | + Dict with full server response |
| 120 | +
|
| 121 | + Notes: |
| 122 | + Check class docstirng for more info |
| 123 | + """ |
| 124 | + return await self._aio_processing_response() |
0 commit comments