commit 9485706a68a7f67be250a4b636697f65df4f8e63 Author: captchasolver Date: Thu Mar 20 22:05:27 2025 +0200 init diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4ab723b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Solvecaptcha + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..01516b8 --- /dev/null +++ b/README.md @@ -0,0 +1,411 @@ +![solvecaptcha-python](https://github.com/user-attachments/assets/b3526dc7-a0aa-4f07-a4f7-51e0ad742941) + + + + + + + + + + +# Python library for interacting with the Solvecaptcha API (captcha-solving service) + +A simple and efficient method to integrate the [Solvecaptcha] captcha-solving service into your code, enabling the automation of solving various types of captchas. +Examples of API requests for different captcha types can be found on the [Python captcha solver](https://solvecaptcha.com/captcha-solver/python-captcha-solver-bypass) page. + +- [Python Library for Interacting with the Solvecaptcha API](#python-library-for-interacting-with-the-solvecaptcha-api-captcha-solving-service) + - [Installation](#installation) + - [Configuration](#configuration) + - [Solvecaptcha instance options](#solvecaptcha-instance-options) + - [Solve captcha](#solve-captcha) + - [Captcha options](#captcha-options) + - [Normal Captcha](#normal-captcha) + - [Text Captcha](#text-captcha) + - [reCAPTCHA v2](#recaptcha-v2) + - [reCAPTCHA v3](#recaptcha-v3) + - [FunCaptcha](#funcaptcha) + - [GeeTest](#geetest) + - [GeeTest v4](#geetest-v4) + - [Cloudflare Turnstile](#cloudflare-turnstile) + - [KeyCaptcha](#keycaptcha) + - [Grid](#grid) + - [ClickCaptcha](#clickcaptcha) + - [Rotate](#rotate) + - [Other methods](#other-methods) + - [send / get_result](#send--get_result) + - [balance](#balance) + - [report](#report) + - [Error handling](#error-handling) + - [Proxies](#proxies) + - [Async calls](#async-calls) + - [Examples](#examples) + + - [Useful articles](#useful-articles) + - [Get in touch](#get-in-touch) + - [License](#license) + +## Installation + +This package can be installed using Pip: + +```bash +pip3 install solvecaptcha-python +``` + +## Configuration + +An instance of `Solvecaptcha` can be created as follows: + +```python +from solvecaptcha import Solvecaptcha + +solver = Solvecaptcha('YOUR_API_KEY') +``` + +Additionally, there are several options available for configuration: + +```python +config = { + 'server': 'solvecaptcha.com', + 'apiKey': 'YOUR_API_KEY', + 'callback': 'https://your.site/result-receiver', + 'defaultTimeout': 120, + 'recaptchaTimeout': 600, + 'pollingInterval': 10, + 'extendedResponse': False + } +solver = Solvecaptcha(**config) +``` + +### Solvecaptcha instance options + +| Option | Default value | Description | +| ---------------- | ------------------ | -------------- | +| server | `solvecaptcha.com` | API server. You can configure it to `solvecaptcha.com` if your account is registered on this platform. | +| callback | - | The URL of your web server that receives the captcha recognition result. This URL must first be registered in your account's [pingback settings]. | +| defaultTimeout | 120 | Polling timeout in seconds for all captcha types except reCAPTCHA. Specifies the duration for which the module attempts to retrieve the response from the `res.php` API endpoint. | +| recaptchaTimeout | 600 | Polling timeout for reCAPTCHA in seconds. Specifies the duration for which the module attempts to retrieve the response from the `res.php` API endpoint. | +| pollingInterval | 10 | Interval in seconds between requests to the `res.php` API endpoint. It is not recommended to set a value lower than 5 seconds. | +| extendedResponse | None | Set to `True` to receive the response with additional fields or in a more structured format (enables `JSON` response from the `res.php` API endpoint). Recommended for [ClickCaptcha](#clickcaptcha) and [Canvas](#canvas). | + +> [!IMPORTANT] +> Once `callback` is defined for the `Solvecaptcha` instance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL. + +To get the answer manually, use the [get_result method](#send--get_result). + +## Solve captcha + +When submitting any image-based CAPTCHA, you can provide additional options to assist Solvecaptcha workers in solving it correctly. + +### Captcha options + +| Option | Default Value | Description | +| ------------- | ------------- | --------------------------------------------------------------------------------------------- | +| numeric | 0 | Specifies whether the captcha consists only of numbers or includes other symbols. More details are available in the [API documentation][post options]. | +| minLen | 0 | Sets the minimum length of the expected answer. | +| maxLen | 0 | Sets the maximum length of the expected answer. | +| phrase | 0 | Indicates whether the response consists of multiple words. | +| caseSensitive | 0 | Determines if the response must match the original case. | +| calc | 0 | Specifies if the captcha involves a mathematical calculation. | +| lang | - | Defines the language of the captcha. Refer to the [list of supported languages]. | +| hintImg | - | Provides an additional image as a hint for workers alongside the captcha. | +| hintText | - | Displays a text hint or task description for workers along with the captcha. | + + +Below, you can find basic examples for each captcha type. For more examples with all available options, check the [examples directory]. + +### Normal Captcha + +[API method description.](https://solvecaptcha.com/captcha-solver-api#solving_normal_captcha) + +To solve a standard captcha (distorted text on an image), use the following method. This method can also be applied for text recognition in any image. + + +```python +result = solver.normal('path/to/captcha.jpg', param1=..., ...) +# OR +result = solver.normal('https://site-with-captcha.com/path/to/captcha.jpg', param1=..., ...) +``` + +```python +result = solver.audio('path/to/captcha.mp3', lang = 'lang', param1=..., ...) +# OR +result = solver.audio('https://site-with-captcha.com/path/to/captcha.mp3', lang = 'lang', param1=..., ...) +``` + +### Text Captcha + +[API method description.](https://solvecaptcha.com/captcha-solver-api#solving_text_captcha) + +This method can be used to solve captchas that require answering a question presented in plain text. + +```python +result = solver.text('If tomorrow is Saturday, what day is today?', param1=..., ...) +``` + +### reCAPTCHA v2 + +[API method description.](https://solvecaptcha.com/captcha-solver-api#solving_recaptchav2_new) + +Use the following method to solve reCAPTCHA V2 and retrieve a token for bypassing the protection. + +```python +result = solver.recaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', + url='https://mysite.com/page/with/recaptcha', + param1=..., ...) +``` + +### reCAPTCHA v3 + +[API method description.](https://solvecaptcha.com/captcha-solver-api#solving_recaptchav3) + +This method offers a reCAPTCHA V3 solver and returns a token. + +```python +result = solver.recaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', + url='https://mysite.com/page/with/recaptcha', + version='v3', + param1=..., ...) +``` + +### FunCaptcha + +[API method description.](https://solvecaptcha.com/captcha-solver-api#solving_funcaptcha_new) + +FunCaptcha (Arkoselabs) solving method that returns a token. + +```python +result = solver.funcaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', + url='https://mysite.com/page/with/funcaptcha', + param1=..., ...) + +``` + +### GeeTest + +[API method description.](https://solvecaptcha.com/captcha-solver-api#solving_geetest) + +Method for solving GeeTest puzzle captcha. Returns a set of tokens in JSON format. + +```python +result = solver.geetest(gt='f1ab2cdefa3456789012345b6c78d90e', + challenge='12345678abc90123d45678ef90123a456b', + url='https://www.site.com/page/', + param1=..., ...) + +``` + +### GeeTest v4 + +[API method description.](https://solvecaptcha.com/captcha-solver-api#solving_geetest_v4) + +Use this method to solve GeeTest v4. The response is returned in JSON format. + +```python +result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73', + url='https://www.site.com/page/', + param1=..., ...) + +``` + +### Cloudflare Turnstile + +[API method description.](https://solvecaptcha.com/captcha-solver-api#solving_cloudflare_turnstile) + +Use this method to solve Cloudflare Turnstile. The response is returned as JSON containing the token. + +```python +result = solver.turnstile(sitekey='0x1AAAAAAAAkg0s2VIOD34y5', + url='http://mysite.com/', + data='foo', + pagedata='bar', + action='challenge', + useragent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36') +``` + +### KeyCaptcha + +[API method description.](https://solvecaptcha.com/captcha-solver-api#solving_keycaptcha) + +Token-based method for solving KeyCaptcha. + +```python +result = solver.keycaptcha(s_s_c_user_id=10, + s_s_c_session_id='493e52c37c10c2bcdf4a00cbc9ccd1e8', + s_s_c_web_server_sign='9006dc725760858e4c0715b835472f22-pz-', + s_s_c_web_server_sign2='2ca3abe86d90c6142d5571db98af6714', + url='https://www.keycaptcha.ru/demo-magnetic/', + param1=..., ...) + +``` + +### Grid + +[API method description.](https://solvecaptcha.com/captcha-solver-api#solving_grid) + +The grid method was initially known as the Old reCAPTCHA V2 method. It can be used to bypass any captcha that requires selecting specific grid boxes on an image. Returns the numbers of the selected boxes. + +```python +result = solver.grid('path/to/captcha.jpg', param1=..., ...) +``` + +### ClickCaptcha + +[API method description.](https://solvecaptcha.com/captcha-solver-api#solving_clickcaptcha) + +The ClickCaptcha method returns the coordinates of specific points on the captcha image. It is useful when solving captchas that require clicking on designated areas within the image. + +```python +result = solver.coordinates('path/to/captcha.jpg', param1=..., ...) +``` + +### Rotate + +[API method description.](https://solvecaptcha.com/captcha-solver-api#solving_rotatecaptcha) + +This method is used to solve captchas that require rotating an object. It is primarily utilized for bypassing FunCaptcha and returns the rotation angle. + +```python +result = solver.rotate('path/to/captcha.jpg', param1=..., ...) +``` + +### Canvas + +[API method description.](https://solvecaptcha.com/captcha-solver-api#canvas) + +The canvas method is used for captchas that require drawing a line around an object in an image. It returns a set of point coordinates for constructing a polygon. + +```python +result = solver.canvas('path/to/captcha.jpg', param1=..., ...) +``` + +## Other methods + +### send / get_result + +These methods allow manual captcha submission and answer polling. The `send()` method supports sending any captcha type. To specify the captcha type, you must manually set the `method` parameter, for example, `method='recaptcha'` for solving reCAPTCHA. +You can find the available values for the `method` parameter in the [API documentation](https://solvecaptcha.com/captcha-solver-api). + +Example of manually solving a Normal captcha: + +```python +import time +. . . . . + + +id = solver.send(file='path/to/captcha.jpg') +time.sleep(20) + +code = solver.get_result(id) +``` + +### balance + +[API method description.](https://solvecaptcha.com/captcha-solver-api#additional) + +Use this method to retrieve your account balance. + +```python +balance = solver.balance() +``` + +### report + +[API method description.](https://solvecaptcha.com/captcha-solver-api#complain) + +Use this method to report whether a captcha answer was correct or incorrect. + +```python +solver.report(id, True) # captcha solved correctly +solver.report(id, False) # captcha solved incorrectly +``` + +## Error handling + +If an error occurs, the captcha solver throws an exception. Proper error handling is essential. We recommend using `try except` to manage exceptions. +A complete list of possible errors can be found in the [API documentation](https://solvecaptcha.com/captcha-solver-api#error_handling). + +```python +try: + result = solver.text('If tomorrow is Saturday, what day is today?') +except ValidationException as e: + # invalid parameters passed + print(e) +except NetworkException as e: + # network error occurred + print(e) +except ApiException as e: + # api respond with error + print(e) +except TimeoutException as e: + # captcha is not solved so far + print(e) +``` + +## Proxies + +You can provide your proxy as an additional argument for the following methods: reCAPTCHA, FunCaptcha, GeeTest, GeeTest v4, KeyCaptcha, hCaptcha, Turnstile, Amazon WAF, and other captchas. + +The proxy will be passed to the API to facilitate captcha solving. + +We also offer our own proxies that you can use. + +```python +proxy={ + 'type': 'HTTPS', + 'uri': 'login:password@IP_address:PORT' +} +``` + +## Async calls + +You can also perform asynchronous calls using [asyncio], for example: + +```python +import asyncio +import concurrent.futures +from solvecaptcha import Solvecaptcha + +API_KEY = "YOUR_API_KEY" +image = "data:image/png;base64,iVBORw0KGgoA..." + +async def captchaSolver(image): + loop = asyncio.get_running_loop() + with concurrent.futures.ThreadPoolExecutor() as pool: + result = await loop.run_in_executor(pool, lambda: Solvecaptcha(API_KEY).normal(image)) + return result + +captcha_result = asyncio.run(captchaSolver(image)) +``` + +## Examples + +Examples of solving all supported captcha types can be found in the [examples] directory. + + + +## Useful articles + +- [Solve and bypass Google reCAPTCHA, hCaptcha, Image CAPTCHA, Cloudflare Challenge and any captcha in Selenium with captcha solver.](https://solvecaptcha.com/captcha-solver/selenium-captcha-solver-bypass) +- [Solve and bypass Google reCAPTCHA, hCaptcha, Arkose FunCaptcha, Cloudflare Turnstile, and any captcha in Puppeteer with captcha solver.](https://solvecaptcha.com/captcha-solver/puppeteer-captcha-solver-bypass) + +## Get in touch + + + + +## License + +The code in this repository is licensed under the MIT License. For more details, see the [LICENSE](./LICENSE) file. + + +[Solvecaptcha]: https://solvecaptcha.com/ +[pingback settings]: https://solvecaptcha.com/captcha-solver-api#manage_pingback +[post options]: https://solvecaptcha.com/captcha-solver-api#normal_post +[list of supported languages]: https://solvecaptcha.com/captcha-solver-api#language +[examples directory]: /examples +[asyncio]: https://docs.python.org/3/library/asyncio.html +[examples]: ./examples diff --git a/examples/canvas.py b/examples/canvas.py new file mode 100644 index 0000000..a8c8460 --- /dev/null +++ b/examples/canvas.py @@ -0,0 +1,26 @@ +import sys +import os +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.canvas('./images/canvas.jpg', hintText='Draw around apple') + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/canvas_base64.py b/examples/canvas_base64.py new file mode 100644 index 0000000..5268606 --- /dev/null +++ b/examples/canvas_base64.py @@ -0,0 +1,31 @@ +import sys +import os +from base64 import b64encode + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +with open('./images/canvas.jpg', 'rb') as f: + b64 = b64encode(f.read()).decode('utf-8') + +try: + result = solver.canvas(b64, hintText='Draw around apple') + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/canvas_options.py b/examples/canvas_options.py new file mode 100644 index 0000000..e176b62 --- /dev/null +++ b/examples/canvas_options.py @@ -0,0 +1,33 @@ +import sys +import os +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key, defaultTimeout=120, pollingInterval=5, server='solvecaptcha.com') + +try: + result = solver.canvas( + './images/canvas.jpg', + previousId=0, + canSkip=0, + lang='en', + hintImg='./images/canvas_hint.jpg', + hintText='Draw around apple', + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/coordinates.py b/examples/coordinates.py new file mode 100644 index 0000000..e295da1 --- /dev/null +++ b/examples/coordinates.py @@ -0,0 +1,26 @@ +import sys +import os +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.coordinates('./images/grid.jpg') + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/coordinates_base64.py b/examples/coordinates_base64.py new file mode 100644 index 0000000..ede301c --- /dev/null +++ b/examples/coordinates_base64.py @@ -0,0 +1,31 @@ +import sys +import os +from base64 import b64encode + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +with open('./images/grid.jpg', 'rb') as f: + b64 = b64encode(f.read()).decode('utf-8') + +try: + result = solver.coordinates(b64) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/coordinates_options.py b/examples/coordinates_options.py new file mode 100644 index 0000000..e750cfc --- /dev/null +++ b/examples/coordinates_options.py @@ -0,0 +1,29 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key, defaultTimeout=120, pollingInterval=5, extendedResponse=True) + +try: + result = solver.coordinates('./images/grid_2.jpg', + lang='en', + hintImg='./images/grid_hint.jpg', + hintText='Select all images with an Orange') +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/funcaptcha.py b/examples/funcaptcha.py new file mode 100644 index 0000000..764f95c --- /dev/null +++ b/examples/funcaptcha.py @@ -0,0 +1,29 @@ +import sys +import os +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.funcaptcha(sitekey='1C2BB537-D5F7-4A66-BC74-25881B58F1D6', + url='https://agoda-api.arkoselabs.com/v2/1C2BB537-D5F7-4A66-BC74-25881B58F1D6/api.js', + surl='https://client-api.arkoselabs.com') + + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/funcaptcha_options.py b/examples/funcaptcha_options.py new file mode 100644 index 0000000..7c941b2 --- /dev/null +++ b/examples/funcaptcha_options.py @@ -0,0 +1,36 @@ +import sys +import os +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key, defaultTimeout=180, pollingInterval=15) + +try: + result = solver.funcaptcha( + sitekey='1C2BB537-D5F7-4A66-BC74-25881B58F1D6', + url='https://agoda-api.arkoselabs.com/v2/1C2BB537-D5F7-4A66-BC74-25881B58F1D6/api.js', + surl='https://client-api.arkoselabs.com', + userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36', + # **{'data[key]': 'value'}, #optional data param used by some websites + # proxy={ + # 'type': 'HTTP', + # 'uri': 'login:password@123.123.123.123:8080' + # } + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/geetest.py b/examples/geetest.py new file mode 100644 index 0000000..5de017a --- /dev/null +++ b/examples/geetest.py @@ -0,0 +1,37 @@ +import sys +import os +import requests +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +""" +Important: The value of the 'challenge' parameter is dynamic. You must obtain a new value for each request to our API. +""" + +resp = requests.get("https://mysite.com/api/v1/ captcha-demo/gee-test/init-params") +challenge = resp.json()['challenge'] + +try: + result = solver.geetest(gt='81388ea1fc187e0c335c0a8907ff2625', + apiServer='http://api.geetest.com', + challenge=challenge, + url='https://mysite.com/page/with//geetest') + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) \ No newline at end of file diff --git a/examples/geetest_options.py b/examples/geetest_options.py new file mode 100644 index 0000000..c407b99 --- /dev/null +++ b/examples/geetest_options.py @@ -0,0 +1,46 @@ +import sys +import os +import requests +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key, + defaultTimeout=300, + pollingInterval=10, + extendedResponse=True) + +""" +**Important:** The value of the `challenge` parameter is dynamic. You must obtain a new value for each request to our API. +""" + +resp = requests.get("https://mysite.com/api/v1/ captcha-demo/gee-test/init-params") +challenge = resp.json()['challenge'] + +try: + result = solver.geetest( + gt='81388ea1fc187e0c335c0a8907ff2625', + apiServer='http://api.geetest.com', + challenge=challenge, + url='https://mysite.com/page/with//geetest', + # proxy={ + # 'type': 'HTTPS', + # 'uri': 'login:password@IP_address:PORT' + # } + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) \ No newline at end of file diff --git a/examples/geetest_v4.py b/examples/geetest_v4.py new file mode 100644 index 0000000..126a2e9 --- /dev/null +++ b/examples/geetest_v4.py @@ -0,0 +1,28 @@ +import sys +import os +import requests +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73', + url='https://mysite.com/page/with//geetest-v4') + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/geetest_v4_options.py b/examples/geetest_v4_options.py new file mode 100644 index 0000000..12c9412 --- /dev/null +++ b/examples/geetest_v4_options.py @@ -0,0 +1,42 @@ +import sys +import os +import requests +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +config = { + 'server': 'solvecaptcha.com', + 'apiKey': api_key, + # 'callback': 'https://your.site/result-receiver', # If set, the solver will return only the `captchaId` without polling the API for the answer. + 'defaultTimeout': 120, + 'recaptchaTimeout': 600, + 'pollingInterval': 10, + } + +solver = Solvecaptcha(**config) + +try: + result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73', + url='https://mysite.com/page/with//geetest-v4', + # proxy={ + # 'type': 'HTTPS', + # 'uri': 'login:password@IP_address:PORT' + # } + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/grid.py b/examples/grid.py new file mode 100644 index 0000000..0f1554c --- /dev/null +++ b/examples/grid.py @@ -0,0 +1,30 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.grid('./images/grid_2.jpg', + hintText='Select all images with an Orange', + rows=3, + cols=3) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/grid_base64.py b/examples/grid_base64.py new file mode 100644 index 0000000..4c21d74 --- /dev/null +++ b/examples/grid_base64.py @@ -0,0 +1,34 @@ +import sys +import os +from base64 import b64encode + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +with open('./images/grid_2.jpg', 'rb') as f: + b64 = b64encode(f.read()).decode('utf-8') + +try: + result = solver.grid(b64, + hintText='Select all images with an Orange', + rows=3, + cols=3) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/grid_options.py b/examples/grid_options.py new file mode 100644 index 0000000..78e4230 --- /dev/null +++ b/examples/grid_options.py @@ -0,0 +1,36 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key, defaultTimeout=100, pollingInterval=12) + +try: + result = solver.grid( + file='./images/grid_2.jpg', + rows=3, + cols=3, + previousId=0, + canSkip=0, + lang='en', + hintImg='./images/grid_hint.jpg', + # hintText='Select all images with an Orange', + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/hcaptcha.py b/examples/hcaptcha.py new file mode 100644 index 0000000..0015d4b --- /dev/null +++ b/examples/hcaptcha.py @@ -0,0 +1,34 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.hcaptcha( + sitekey='bf8ccfbf-6a05-45f6-982a-7a7964c2f50c', + url='https://portalunico.siscomex.gov.br', + ) + + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) + + + diff --git a/examples/hcaptcha_options.py b/examples/hcaptcha_options.py new file mode 100644 index 0000000..ea6dbf5 --- /dev/null +++ b/examples/hcaptcha_options.py @@ -0,0 +1,49 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +config = { + 'server': 'solvecaptcha.com', + 'apiKey': api_key, + # 'callback': 'https://your.site/result-receiver', # If set, the solver will return only the `captchaId` without polling the API for the answer. + 'defaultTimeout': 120, + 'recaptchaTimeout': 600, + 'pollingInterval': 10, + } + +solver = Solvecaptcha(**config) + +try: + result = solver.hcaptcha( + sitekey='bf8ccfbf-6a05-45f6-982a-7a7964c2f50c', + url='https://portalunico.siscomex.gov.br', + invisible=0, + domain="hcaptcha.com", + # proxy={ + # 'type': 'HTTPS', + # 'uri': 'login:password@IP_address:PORT' + # } + ) + + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) + + + diff --git a/examples/images/canvas.jpg b/examples/images/canvas.jpg new file mode 100644 index 0000000..8d4a70d Binary files /dev/null and b/examples/images/canvas.jpg differ diff --git a/examples/images/canvas_hint.jpg b/examples/images/canvas_hint.jpg new file mode 100644 index 0000000..1ecb733 Binary files /dev/null and b/examples/images/canvas_hint.jpg differ diff --git a/examples/images/grid.jpg b/examples/images/grid.jpg new file mode 100644 index 0000000..064e4aa Binary files /dev/null and b/examples/images/grid.jpg differ diff --git a/examples/images/grid_2.jpg b/examples/images/grid_2.jpg new file mode 100644 index 0000000..b9ce668 Binary files /dev/null and b/examples/images/grid_2.jpg differ diff --git a/examples/images/grid_hint.jpg b/examples/images/grid_hint.jpg new file mode 100644 index 0000000..10e9686 Binary files /dev/null and b/examples/images/grid_hint.jpg differ diff --git a/examples/images/normal.jpg b/examples/images/normal.jpg new file mode 100644 index 0000000..f1770b3 Binary files /dev/null and b/examples/images/normal.jpg differ diff --git a/examples/images/normal_2.jpg b/examples/images/normal_2.jpg new file mode 100644 index 0000000..a1f5035 Binary files /dev/null and b/examples/images/normal_2.jpg differ diff --git a/examples/images/rotate.jpg b/examples/images/rotate.jpg new file mode 100644 index 0000000..08427e6 Binary files /dev/null and b/examples/images/rotate.jpg differ diff --git a/examples/keycaptcha.py b/examples/keycaptcha.py new file mode 100644 index 0000000..625ae5b --- /dev/null +++ b/examples/keycaptcha.py @@ -0,0 +1,32 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.keycaptcha( + s_s_c_user_id=184015, + s_s_c_session_id='e34ddd2c72e67593ac0b4ca8e4f44725', + s_s_c_web_server_sign='a5ebd41ae22348b2cdbdc211792e982d', + s_s_c_web_server_sign2='29255689423dd92990f8d06de50560d0', + url='https://mysite.com/page/with//keycaptcha') + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/keycaptcha_options.py b/examples/keycaptcha_options.py new file mode 100644 index 0000000..5979012 --- /dev/null +++ b/examples/keycaptcha_options.py @@ -0,0 +1,47 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + + +config = { + 'server': 'solvecaptcha.com', + 'apiKey': api_key, + # 'callback': 'https://your.site/result-receiver', # If set, the solver will return only the `captchaId` without polling the API for the answer. + 'defaultTimeout': 120, + 'recaptchaTimeout': 600, + 'pollingInterval': 10, + } + +solver = Solvecaptcha(**config) + +try: + result = solver.keycaptcha(s_s_c_user_id=184015, + s_s_c_session_id='e34ddd2c72e67593ac0b4ca8e4f44725', + s_s_c_web_server_sign='a5ebd41ae22348b2cdbdc211792e982d', + s_s_c_web_server_sign2='29255689423dd92990f8d06de50560d0', + url='https://mysite.com/page/with//keycaptcha', + # proxy = {'type': 'HTTPS', + # 'uri': 'login:password@IP_address:PORT'} + ) + + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) + + \ No newline at end of file diff --git a/examples/normal.py b/examples/normal.py new file mode 100644 index 0000000..65f7032 --- /dev/null +++ b/examples/normal.py @@ -0,0 +1,27 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.normal('./images/normal.jpg') + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/normal_base64.py b/examples/normal_base64.py new file mode 100644 index 0000000..21c0e70 --- /dev/null +++ b/examples/normal_base64.py @@ -0,0 +1,31 @@ +import sys +import os +from base64 import b64encode + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +with open('./images/normal.jpg', 'rb') as f: + b64 = b64encode(f.read()).decode('utf-8') + +try: + result = solver.normal(b64) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/normal_options.py b/examples/normal_options.py new file mode 100644 index 0000000..92046eb --- /dev/null +++ b/examples/normal_options.py @@ -0,0 +1,38 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key, defaultTimeout=30, pollingInterval=5) + +try: + result = solver.normal( + './images/normal_2.jpg', + numeric=4, + minLen=4, + maxLen=20, + phrase=0, + caseSensitive=0, + calc=0, + lang='en', + # hintImg='./images/normal_hint.jpg', + # hintText='Type red symbols only', + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/recaptcha_v2.py b/examples/recaptcha_v2.py new file mode 100644 index 0000000..2ddcfca --- /dev/null +++ b/examples/recaptcha_v2.py @@ -0,0 +1,33 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.recaptcha( + sitekey='6LdO5_IbAAAAAAeVBL9TClS19NUTt5wswEb3Q7C5', + url='https://mysite.com/page/with/recaptcha-v2' + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) + + + diff --git a/examples/recaptcha_v2_options.py b/examples/recaptcha_v2_options.py new file mode 100644 index 0000000..8d59fea --- /dev/null +++ b/examples/recaptcha_v2_options.py @@ -0,0 +1,46 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + + +config = { + 'server': 'solvecaptcha.com', + 'apiKey': api_key, + # 'callback': 'https://your.site/result-receiver', # If set, the solver will return only the `captchaId` without polling the API for the answer. + 'defaultTimeout': 120, + 'recaptchaTimeout': 600, + 'pollingInterval': 10, + } + +solver = Solvecaptcha(**config) + +try: + result = solver.recaptcha( + sitekey='6LdO5_IbAAAAAAeVBL9TClS19NUTt5wswEb3Q7C5', + url='https://mysite.com/page/with//recaptcha-v2-invisible', + invisible=1, + # header_acao=1, + # pingback="http://mysite.com/pingback/url/", + # proxy={'type': 'HTTPS', + # 'uri': 'login:password@IP_address:PORT' + # } + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/recaptcha_v3.py b/examples/recaptcha_v3.py new file mode 100644 index 0000000..8da27ef --- /dev/null +++ b/examples/recaptcha_v3.py @@ -0,0 +1,31 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.recaptcha( + sitekey='6LfdxboZAAAAAMtnONIt4DJ8J1t4wMC-kVG02zIO', + url='https://mysite.com/page/with//recaptcha-v3', + action='login', + version='v3') + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/recaptcha_v3_options.py b/examples/recaptcha_v3_options.py new file mode 100644 index 0000000..1c2626a --- /dev/null +++ b/examples/recaptcha_v3_options.py @@ -0,0 +1,46 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + + +config = { + 'server': 'solvecapcha.com', + 'apiKey': api_key, + # 'callback': 'https://your.site/result-receiver', # If set, the solver will return only the `captchaId` without polling the API for the answer. + 'defaultTimeout': 120, + 'recaptchaTimeout': 600, + 'pollingInterval': 10, + } + +solver = Solvecaptcha(**config) + +try: + result = solver.recaptcha( + sitekey='6LfdxboZAAAAAMtnONIt4DJ8J1t4wMC-kVG02zIO', + url='https://mysite.com/page/with//recaptcha-v3', + version='v3', + action='verify', + # proxy={ + # 'type': 'HTTPS', + # 'uri': 'login:password@IP_address:PORT' + # } + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/rotate.py b/examples/rotate.py new file mode 100644 index 0000000..3d81db2 --- /dev/null +++ b/examples/rotate.py @@ -0,0 +1,27 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.rotate('./images/rotate.jpg') + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/rotate_options.py b/examples/rotate_options.py new file mode 100644 index 0000000..78a8a9c --- /dev/null +++ b/examples/rotate_options.py @@ -0,0 +1,32 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key, defaultTimeout=100, pollingInterval=10) + +try: + result = solver.rotate( + './images/rotate.jpg', + angle=40, + lang='en', + # hintImg = 'images/rotate_hint.jpg' + hintText='Put the images in the correct way up') + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/text.py b/examples/text.py new file mode 100644 index 0000000..cc6c8bc --- /dev/null +++ b/examples/text.py @@ -0,0 +1,28 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.text('If tomorrow is Saturday, what day is today?') + +except Exception as e: + sys.exit(e) + +else: + print(result) + sys.exit('result: ' + str(result)) diff --git a/examples/text_options.py b/examples/text_options.py new file mode 100644 index 0000000..9ea6f0f --- /dev/null +++ b/examples/text_options.py @@ -0,0 +1,28 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key, defaultTimeout=50, pollingInterval=10) + +try: + result = solver.text('If tomorrow is Saturday, what day is today?', + lang='en') + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/turnstile.py b/examples/turnstile.py new file mode 100644 index 0000000..d622c42 --- /dev/null +++ b/examples/turnstile.py @@ -0,0 +1,33 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + +solver = Solvecaptcha(api_key) + +try: + result = solver.turnstile( + sitekey='0x4AAAAAAAFhFmVSpJiMM20Z', + url='https://tvboom.net/packages/view/id/1/packages/view/id/1/', + useragent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", + ) + +# {"sitekey":"0x4AAAAAAAFhFmVSpJiMM20Z","pageurl":"https:\/\/tvboom.net\/packages\/view\/id\/1\/packages\/view\/id\/1\/","pagedata":"","captchatype":"turnstile","data":"","action":"",","proxy":"","proxytype":"HTTP"} + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/examples/turnstile_options.py b/examples/turnstile_options.py new file mode 100644 index 0000000..0c1f62c --- /dev/null +++ b/examples/turnstile_options.py @@ -0,0 +1,47 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +# In this example, we store the API key in environment variables, which can be set as follows: +# On Linux or macOS: +# export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# On Windows: +# set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 +# Alternatively, you can directly assign the API key to a variable: +# api_key = "1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') + + +config = { + 'server': 'solvecaptcha.com', + 'apiKey': api_key, + # 'callback': 'https://your.site/result-receiver', # If set, the solver will return only the `captchaId` without polling the API for the answer. + 'defaultTimeout': 120, + 'recaptchaTimeout': 600, + 'pollingInterval': 10, + } + +solver = Solvecaptcha(**config) + +try: + result = solver.turnstile(sitekey='0x4AAAAAAADnPIDROrmt1LDg', + url='https://dexscreener.com/', + data="8ffc47422ae4e297", + pagedata="JD.BAzfWHWAX2ZIXTgOkwU7SIJIXB3TYI6x0fplCxPo-1736508032-1.3.1.1-2Qy7twd2XO5laG9G6QrjYSQ.g3LszfU1A1osszzbbz.EHIJLRM4lHyZMnyTex7nIl7U8xVZrb99.lVWJ6RSSWG.0x_95kiDv.kqnQACTDl072eVFdyd1IRA.3SJsKl0ptevnsQx6pShakPgm2HWX65d5Jv.CDvbLLPSDz1SJk35ULnsY0fC9B_7NfgjEai5D2sYdYx5XxIIOOrQLkOHD963SqC6DQu9VXq09o8qlWsjHEORy_4VOsxf.7hjBw9y3Auziyh7ISo2mgAEHqCnYMjJtyLDqc4CGSnmYBRvSGMj96KvTLfSx2PCNxwWpUiEHb1WcM9Y1zjyz6.JVos.mjx5MDQ3UADASMJbtdWHMpH0yDfiDgtWNpxW1F.chfJ.q5MhSip4lLAXMVYLMDi.10C0pjIhwOHM0tuFhbyjAoq7MOfvL9t0sNQLKlrk1RUayK6alVy2Y0Zf1BH4p7lOSPQ", + action="managed", + useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + # proxy={ + # 'type': 'HTTPS', + # 'uri': 'login:password@IP_address:PORT' + # } + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1480256 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests>=2.20.0 \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c61f417 --- /dev/null +++ b/setup.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +from setuptools import setup, find_packages +import re + +with open("README.md", "r") as fh: + long_description = fh.read() + + +def get_version(): + with open('solvecaptcha/__init__.py', 'r') as f: + return re.search(r'__version__ = ["\'](.*?)["\']', f.read()).group(1) + + +setup(name='solvecaptcha-python', + version=get_version(), + description='Python module for easy integration with solvecaptcha.com API', + long_description=long_description, + long_description_content_type="text/markdown", + url='https://github.com/solvercaptcha/solvecaptcha-python/', + install_requires=['requests'], + author='solvecaptcha.com', + author_email='info@solvecaptcha.com', + packages=find_packages(), + include_package_data=True, + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Scientific/Engineering :: Image Recognition", + "Topic :: Utilities", + "Intended Audience :: Developers", + ], + keywords=[ + 'solvecaptcha', 'captcha', 'api', 'captcha solver', 'reCAPTCHA', + 'FunCaptcha', 'Geetest', 'image captcha', 'Coordinates', 'Click Captcha', + 'Geetest V4', 'Lemin captcha', 'Amazon WAF', 'Cloudflare Turnstile', + 'hcaptcha'], + python_requires='>=3.6', + test_suite='tests') diff --git a/solvecaptcha/__init__.py b/solvecaptcha/__init__.py new file mode 100644 index 0000000..d364224 --- /dev/null +++ b/solvecaptcha/__init__.py @@ -0,0 +1,3 @@ +from .api import ApiClient +from .solver import (Solvecaptcha, SolverExceptions, ValidationException, + NetworkException, ApiException, TimeoutException) \ No newline at end of file diff --git a/solvecaptcha/api.py b/solvecaptcha/api.py new file mode 100644 index 0000000..d7eca11 --- /dev/null +++ b/solvecaptcha/api.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 + +import requests + + +class NetworkException(Exception): + pass + + +class ApiException(Exception): + pass + + +class ApiClient(): + def __init__(self, post_url='api.solvecaptcha.com'): + self.post_url = post_url + + def in_(self, files={}, **kwargs): + ''' + + sends POST-request (files and/or params) to solve captcha + + Parameters + ---------- + files : TYPE, optional + DESCRIPTION. The default is {}. + **kwargs : TYPE + DESCRIPTION. + + Raises + ------ + NetworkException + DESCRIPTION. + ApiException + DESCRIPTION. + + Returns + ------- + resp : TYPE + DESCRIPTION. + + ''' + + try: + current_url = 'https://' + self.post_url + '/in.php' + if files: + + files = {key: open(path, 'rb') for key, path in files.items()} + resp = requests.post(current_url, + data=kwargs, + files=files) + + [f.close() for f in files.values()] + + elif 'file' in kwargs: + + with open(kwargs.pop('file'), 'rb') as f: + resp = requests.post(current_url, + data=kwargs, + files={'file': f}) + + else: + resp = requests.post(current_url, + data=kwargs) + + except requests.RequestException as e: + raise NetworkException(e) + + if resp.status_code != 200: + raise NetworkException(f'bad response: {resp.status_code}') + + resp = resp.content.decode('utf-8') + + if 'ERROR' in resp: + raise ApiException(resp) + + return resp + + def res(self, **kwargs): + ''' + sends additional GET-requests (solved captcha, balance, report etc.) + + Parameters + ---------- + **kwargs : TYPE + DESCRIPTION. + + Raises + ------ + NetworkException + DESCRIPTION. + ApiException + DESCRIPTION. + + Returns + ------- + resp : TYPE + DESCRIPTION. + + ''' + + try: + current_url_out = 'https://' + self.post_url + '/res.php' + resp = requests.get(current_url_out, params=kwargs) + + if resp.status_code != 200: + raise NetworkException(f'bad response: {resp.status_code}') + + resp = resp.content.decode('utf-8') + + if 'ERROR' in resp: + raise ApiException(resp) + + except requests.RequestException as e: + raise NetworkException(e) + + return resp diff --git a/solvecaptcha/solver.py b/solvecaptcha/solver.py new file mode 100644 index 0000000..c2353a3 --- /dev/null +++ b/solvecaptcha/solver.py @@ -0,0 +1,774 @@ +#!/usr/bin/env python3 + +import os, sys +import time +import requests +from base64 import b64encode + + +try: + from .api import ApiClient + +except ImportError: + from api import ApiClient + + +class SolverExceptions(Exception): + pass + + +class ValidationException(SolverExceptions): + pass + + +class NetworkException(SolverExceptions): + pass + + +class ApiException(SolverExceptions): + pass + + +class TimeoutException(SolverExceptions): + pass + + +class Solvecaptcha(): + def __init__(self, + apiKey, + softId=1000001, + callback=None, + defaultTimeout=120, + recaptchaTimeout=600, + pollingInterval=10, + server = 'api.solvecaptcha.com', + extendedResponse=None): + + self.API_KEY = apiKey + self.soft_id = softId + self.callback = callback + self.default_timeout = defaultTimeout + self.recaptcha_timeout = recaptchaTimeout + self.polling_interval = pollingInterval + self.api_client = ApiClient(post_url = str(server)) + self.max_files = 9 + self.exceptions = SolverExceptions + self.extendedResponse = extendedResponse + + def recaptcha(self, sitekey, url, version='v2', enterprise=0, **kwargs): + '''Wrapper for solving recaptcha (v2, v3). + + Parameters + _______________ + sitekey : str + Value of sitekey parameter you found on page. + url : str + Full URL of the page where you see the reCAPTCHA. + domain : str, optional + Domain used to load the captcha: google.com or recaptcha.net. Default: google.com. + invisible : int, optional + 1 - means that reCAPTCHA is invisible. 0 - normal reCAPTCHA. Default: 0. + version : str, optional + v3 — defines that you're sending a reCAPTCHA V3. Default: v2. + enterprise : str, optional + 1 - defines that you're sending reCAPTCHA Enterpise. Default: 0. + action : str, optional + Value of action parameter you found on page. Default: verify. + score : str, only for v3, optional + The score needed for resolution. Currently, it's almost impossible to get token with score higher than 0.3. + Default: 0.4. + cookies : str, only for v2, optional + Your cookies that will be passed to our worker who solve the captha. We also return worker's cookies in the + response if you use json=1. Format: KEY:Value, separator: semicolon, example: KEY1:Value1;KEY2:Value2; + userAgent : str, only for v2, optional + Your userAgent that will be passed to our worker and used to solve the captcha. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + + params = { + 'googlekey': sitekey, + 'url': url, + 'method': 'userrecaptcha', + 'version': version, + 'enterprise': enterprise, + **kwargs, + } + + result = self.solve(timeout=self.recaptcha_timeout, **params) + return result + + def hcaptcha(self, sitekey, url, **kwargs): + '''Wrapper for solving hcaptcha. + + Parameters + __________ + sitekey : str + Value of data-sitekey parameter you found on page. + url : str + Full URL of the page where you bypass the captcha. + invisible : num, optional + Use 1 for invisible version of hcaptcha. Currently it is a very rare case. + Default: 0. + data : str, optional + Custom data that is used in some implementations of hCaptcha, mostly with invisible=1. In most cases you see + it as rqdata inside network requests. Format: "data": "rqDataValue". + domain : str, optional + Domain used to load the captcha: hcaptcha.com or js.hcaptcha.com. Default: hcaptcha.com. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + + result = self.solve(sitekey=sitekey, + url=url, + method='hcaptcha', + **kwargs) + return result + + def turnstile(self, sitekey, url, **kwargs): + '''Wrapper for solving Cloudflare Turnstile. + + Parameters + __________ + sitekey : str + Value of sitekey parameter you found on page. + url : str + Full URL of the page where you see the captcha. + useragent : str + User-Agent of your browser. Must match the User-Agent you use to access the site. + Use only modern browsers released within the last 6 months. + action : str. optional + Value of optional action parameter you found on page, can be defined in data-action attribute or passed + to turnstile.render call. + data : str, optional + The value of cData passed to turnstile.render call. Also can be defined in data-cdata attribute. + pagedata : str, optional + The value of the chlPageData parameter when calling turnstile.render. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + + result = self.solve(sitekey=sitekey, + url=url, + method='turnstile', + **kwargs) + return result + + def geetest(self, gt, challenge, url, **kwargs): + '''Wrapper for solving geetest captcha. + + Parameters: + __________ + gt : str + Value of gt parameter you found on target website. + challenge : str + Value of challenge parameter you found on target website. + url : str + Full URL of the page where you see Geetest captcha. + offline : num, optional + In rare cases initGeetest can be called with offline parameter. If the call uses offline: true, set the + value to 1. Default: 0. + new_captcha : num, optional + In rare cases initGeetest can be called with new_captcha parameter. If the call uses new_captcha: true, set + the value to 1. Mostly used with offline parameter. + userAgent : str, optional + Your userAgent that will be passed to our worker and used to solve the captcha. + apiServer : str, optional + Value of api_server parameter you found on target website. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + + result = self.solve(gt=gt, + challenge=challenge, + url=url, + method='geetest', + **kwargs) + return result + + def geetest_v4(self, captcha_id, url, **kwargs): + '''Wrapper for solving geetest_v4 captcha. + + Parameters + __________ + captcha_id : str + Value of captcha_id parameter you found on target website. + url: str + Full URL of the page where you see Geetest captcha. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + + result = self.solve(captcha_id=captcha_id, + url=url, + method='geetest_v4', + **kwargs) + return result + + def normal(self, file, **kwargs): + '''Wrapper for solving a normal captcha (image). + + Parameters + __________ + file : file + Captcha image file. * required if you submit image as a file (method=post). + body : str + Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64). + phrase : int, optional + 0 - captcha contains one word. 1 - captcha contains two or more words. + Default: 0. + numeric : int, optional + 0 - not specified. 1 - captcha contains only numbers. 2 - captcha contains only letters. 3 - captcha + contains only numbers OR only letters. 4 - captcha MUST contain both numbers AND letters. + Default: 0 + minLen : int, optional + 0 - not specified. 1..20 - minimal number of symbols in captcha. + Default: 0. + maxLen : int, optional + 0 - not specified. 1..20 - maximal number of symbols in captcha. + Default: 0. + caseSensitive : int, optional + 0 - captcha in not case sensitive. 1 - captcha is case sensitive. + Default: 0. + calc : int, optional + 0 - not specified. 1 - captcha requires calculation (e.g. type the result 4 + 8 = ). + Default: 0. + lang : str, optional + Language code. See the list of supported languages https://solvecaptcha.com/captcha-solver-api#language. + hintText : str, optional + Max 140 characters. Endcoding: UTF-8. Text will be shown to worker to help him to solve the captcha correctly. + For example: type red symbols only. + hintImg : img, optional + Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending + instruction as text with textinstructions. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + ''' + + method = self.get_method(file) + result = self.solve(**method, **kwargs) + return result + + def text(self, text, **kwargs): + '''Wrapper for solving text captcha. + + Parameters + __________ + text : str + Max 140 characters. Endcoding: UTF-8. Text will be shown to worker to help him to solve the captcha correctly. + For example: type red symbols only. + lang: str, optional + Language code. See the list of supported languages https://solvecaptcha.com/captcha-solver-api#language. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + ''' + + result = self.solve(text=text, method='post', **kwargs) + return result + + def funcaptcha(self, sitekey, url, **kwargs): + '''Wrapper for solving funcaptcha. + + Parameters + __________ + sitekey : str + Value of pk or data-pkey parameter you found on page. + url : str + Full URL of the page where you see the FunCaptcha. + surl : str, optional + Value of surl parameter you found on page. + userAgent: str, optional + Tells us to use your user-agent value. + data[key] : str, optional + Custom data to pass to FunCaptcha. For example: data[blob]=stringValue. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + + result = self.solve(publickey=sitekey, + url=url, + method='funcaptcha', + **kwargs) + return result + + def keycaptcha(self, s_s_c_user_id, s_s_c_session_id, + s_s_c_web_server_sign, s_s_c_web_server_sign2, url, + **kwargs): + '''Wrapper for solving. + + Parameters + __________ + s_s_c_user_id : str + Value of s_s_c_user_id parameter you found on page. + s_s_c_session_id : str + Value of s_s_c_session_id parameter you found on page. + s_s_c_web_server_sign : str + Value of s_s_c_web_server_sign parameter you found on page. + s_s_c_web_server_sign2 : str + Value of s_s_c_web_server_sign2 parameter you found on page. + url : str + Full URL of the page where you see the KeyCaptcha. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + + params = { + 's_s_c_user_id': s_s_c_user_id, + 's_s_c_session_id': s_s_c_session_id, + 's_s_c_web_server_sign': s_s_c_web_server_sign, + 's_s_c_web_server_sign2': s_s_c_web_server_sign2, + 'url': url, + 'method': 'keycaptcha', + **kwargs, + } + + result = self.solve(**params) + return result + + def grid(self, file, **kwargs): + '''Wrapper for solving grid captcha (image). + + Required: + file : file + Captcha image file. * required if you submit image as a file (method=post). + body : str + Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64). + hintText : str + Max 140 characters. Endcoding: UTF-8. Text with instruction for solving reCAPTCHA. For example: select images + with trees. Not required if you're sending instruction as an image with imginstructions. + hintImg : img + Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending + instruction as text with textinstructions. + rows : int, optional + Number of rows in reCAPTCHA grid. + cols : itn, optional + Number of columns in reCAPTCHA grid. + previousId : str, optional + Id of your previous request with the same captcha challenge. + canSkip : int, optional + 0 - not specified. 1 - possibly there's no images that fit the instruction. Set the value to 1 only if it's + possible that there's no images matching to the instruction. We'll provide a button "No matching images" to + worker, and you will receive No_matching_images as answer. + Default: 0. + lang: str, optional + Language code. See the list of supported languages https://solvecaptcha.com/captcha-solver-api#language. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + + method = self.get_method(file) + + params = { + 'recaptcha': 1, + **method, + **kwargs, + } + + result = self.solve(**params) + return result + + def coordinates(self, file, **kwargs): + '''Wrapper for solving coordinates captcha (image). + + Parameters + __________ + file : file + Captcha image file. * required if you submit image as a file (method=post). + body : str + Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64). + hintText : str + Max 140 characters. Endcoding: UTF-8. Text with instruction for solving the captcha. For example: click on + images with ghosts. Not required if the image already contains the instruction. + hintImg : img + Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending + instruction as text with textinstructions. + lang : str, optional + Language code. See the list of supported languages https://solvecaptcha.com/captcha-solver-api#language. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + ''' + + method = self.get_method(file) + + params = { + 'coordinatescaptcha': 1, + **method, + **kwargs, + } + + result = self.solve(**params) + return result + + def rotate(self, files, **kwargs): + '''Wrapper for solving rotate captcha (image). + + Parameters + __________ + files : file + Captcha image file. * required if you submit image as a file (method=post). + body : str + Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64). + angle : int, optional + Angle for one rotation step in degrees. If not defined we'll use the default value for FunCaptcha: 40 degrees. + Default: 40. + lang : str, optional + Language code. See the list of supported languages https://solvecaptcha.com/captcha-solver-api#language. + hintImg : str, optional + Image with instruction for worker to help him to solve captcha correctly. + hintText : str, optional + Text will be shown to worker to help him to to solve captcha correctly. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + + if isinstance(files, str): + + file = self.get_method(files)['file'] + + result = self.solve(file=file, method='rotatecaptcha', **kwargs) + return result + + elif isinstance(files, dict): + files = list(files.values()) + + files = self.extract_files(files) + + result = self.solve(files=files, method='rotatecaptcha', **kwargs) + return result + + def canvas(self, file, **kwargs): + '''Wrapper for solving canvas captcha (image). + + Parameters + __________ + file : file + Captcha image file. * required if you submit image as a file (method=post). + body : str + Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64). + hintText : str + Max 140 characters. Endcoding: UTF-8. Text with instruction for solving reCAPTCHA. For example: select + images with trees. Not required if you're sending instruction as an image with imginstructions. + hintImg : img + Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending + instruction as text with textinstructions. + canSkip : int, optional + 0 - not specified. 1 - possibly there's no images that fit the instruction. Set the value to 1 only if it's + possible that there's no images matching to the instruction. We'll provide a button "No matching images" to + worker, and you will receive No_matching_images as answer. + Default: 0. + lang : int, optional + 0 - not specified. 1 - Cyrillic captcha. 2 - Latin captcha. + Default: 0. + callback : str, optional + URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on + the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. + ''' + + if not ('hintText' in kwargs or 'hintImg' in kwargs): + raise ValidationException( + 'parameters required: hintText and/or hintImg') + + method = self.get_method(file) + + params = { + 'recaptcha': 1, + 'canvas': 1, + **method, + **kwargs, + } + + result = self.solve(**params) + return result + + def solve(self, timeout=0, polling_interval=0, **kwargs): + '''Sends captcha, receives result. + + Parameters + __________ + timeout : float + + polling_interval : int + + **kwargs : dict + all captcha params + + Returns + + result : string + ''' + + id_ = self.send(**kwargs) + result = {'captchaId': id_} + + if self.callback is None: + timeout = float(timeout or self.default_timeout) + sleep = int(polling_interval or self.polling_interval) + + code = self.wait_result(id_, timeout, sleep) + + if self.extendedResponse == True: + + new_code = { + key if key != 'request' else 'code': value + for key, value in code.items() + if key != 'status' + } + result.update(new_code) + else: + result.update({'code': code}) + + return result + + def wait_result(self, id_, timeout, polling_interval): + + max_wait = time.time() + timeout + + while time.time() < max_wait: + + try: + return self.get_result(id_) + + except NetworkException: + + time.sleep(polling_interval) + + raise TimeoutException(f'timeout {timeout} exceeded') + + def get_method(self, file): + + if not file: + raise ValidationException('File required') + + if not '.' in file and len(file) > 50: + return {'method': 'base64', 'body': file} + + if file.startswith('http'): + img_resp = requests.get(file) + if img_resp.status_code != 200: + raise ValidationException(f'File could not be downloaded from url: {file}') + return {'method': 'base64', 'body': b64encode(img_resp.content).decode('utf-8')} + + if not os.path.exists(file): + raise ValidationException(f'File not found: {file}') + + return {'method': 'post', 'file': file} + + def send(self, **kwargs): + """This method can be used for manual captcha submission + + Parameters + _________ + method : str + The name of the method must be found in the documentation https://solvecaptcha.com/captcha-solver-api + kwargs: dict + All captcha params + Returns + + """ + + params = self.default_params(kwargs) + params = self.rename_params(params) + + params, files = self.check_hint_img(params) + + response = self.api_client.in_(files=files, **params) + + if not response.startswith('OK|'): + raise ApiException(f'cannot recognize response {response}') + + return response[3:] + + def get_result(self, id_): + import json + """This method can be used for manual captcha answer polling. + + Parameters + __________ + id_ : str + ID of the captcha sent for solution + Returns + + answer : text + """ + + if self.extendedResponse == True: + + response = self.api_client.res(key=self.API_KEY, action='get', id=id_, json=1) + + response_data = json.loads(response) + + if response_data.get("status") == 0: + raise NetworkException + + if not response_data.get("status") == 1: + raise ApiException(f'Unexpected status in response: {response_data}') + + return response_data + + else: + + response = self.api_client.res(key=self.API_KEY, action='get', id=id_) + + if response == 'CAPCHA_NOT_READY': + raise NetworkException + + if not response.startswith('OK|'): + raise ApiException(f'cannot recognize response {response}') + + return response[3:] + + def balance(self): + '''Get my balance + + Returns + + balance : float + ''' + + response = self.api_client.res(key=self.API_KEY, action='getbalance') + return float(response) + + def report(self, id_, correct): + '''Report of solved captcha: good/bad. + + Parameters + __________ + id_ : str + captcha ID + + correct : bool + True/False + + Returns + None. + + ''' + + rep = 'reportgood' if correct else 'reportbad' + self.api_client.res(key=self.API_KEY, action=rep, id=id_) + + return + + def rename_params(self, params): + + replace = { + 'caseSensitive': 'regsense', + 'minLen': 'min_len', + 'maxLen': 'max_len', + 'minLength': 'min_len', + 'maxLength': 'max_len', + 'hintText': 'textinstructions', + 'hintImg': 'imginstructions', + 'url': 'pageurl', + 'score': 'min_score', + 'text': 'textcaptcha', + 'rows': 'recaptcharows', + 'cols': 'recaptchacols', + 'previousId': 'previousID', + 'canSkip': 'can_no_answer', + 'apiServer': 'api_server', + 'softId': 'soft_id', + 'callback': 'pingback', + 'datas': 'data-s', + } + + new_params = { + v: params.pop(k) + for k, v in replace.items() if k in params + } + + proxy = params.pop('proxy', '') + proxy and new_params.update({ + 'proxy': proxy['uri'], + 'proxytype': proxy['type'] + }) + + new_params.update(params) + + return new_params + + def default_params(self, params): + + params.update({'key': self.API_KEY}) + + callback = params.pop('callback', self.callback) + soft_id = params.pop('softId', self.soft_id) + + if callback: params.update({'callback': callback}) + if soft_id: params.update({'softId': soft_id}) + + self.has_callback = bool(callback) + + return params + + def extract_files(self, files): + + if len(files) > self.max_files: + raise ValidationException( + f'Too many files (max: {self.max_files})') + + not_exists = [f for f in files if not (os.path.exists(f))] + + if not_exists: + raise ValidationException(f'File not found: {not_exists}') + + files = {f'file_{e+1}': f for e, f in enumerate(files)} + return files + + def check_hint_img(self, params): + + hint = params.pop('imginstructions', None) + files = params.pop('files', {}) + + if not hint: + return params, files + + if not '.' in hint and len(hint) > 50: + params.update({'imginstructions': hint}) + return params, files + + if not os.path.exists(hint): + raise ValidationException(f'File not found: {hint}') + + if not files: + files = {'file': params.pop('file', {})} + + files.update({'imginstructions': hint}) + + return params, files + + +if __name__ == '__main__': + + key = sys.argv[1] + sol = Solvecaptcha(key) \ No newline at end of file diff --git a/tests/abstract.py b/tests/abstract.py new file mode 100755 index 0000000..6806489 --- /dev/null +++ b/tests/abstract.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +import unittest +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from solvecaptcha import Solvecaptcha + +captcha_id = '123' +code = 'abcd' + + +class ApiClient(): + def in_(self, files={}, **kwargs): + + self.incomings = kwargs + self.incoming_files = files + + return 'OK|' + captcha_id + + def res(self, **kwargs): + + return 'OK|' + code # {'code': code} + + +class AbstractTest(unittest.TestCase): + def setUp(self): + + self.solver = Solvecaptcha('API_KEY', pollingInterval=1) + self.solver.api_client = ApiClient() + + def send_return(self, for_send, method, **kwargs): + + file = kwargs.pop('file', {}) + file = kwargs.pop('files', file) + + result = method(file, **kwargs) if file else method(**kwargs) + + incomings = self.solver.api_client.incomings + for_send.update({'key': 'API_KEY'}) + for_send.update({'soft_id': 1000001}) + + files = for_send.pop('files', {}) + self.assertEqual(incomings, for_send) + + incoming_files = self.solver.api_client.incoming_files + incoming_files and self.assertEqual(incoming_files, files) + + self.assertIsInstance(result, dict) + self.assertIn('code', result) + self.assertEqual(result['code'], code) + + def invalid_file(self, method, **kwargs): + + self.assertRaises(self.solver.exceptions, method, 'lost_file', + **kwargs) + + def too_many_files(self, method, **kwargs): + + files = ['../examples/images/rotate.jpg'] * (self.solver.max_files + 1) + self.assertRaises(self.solver.exceptions, method, files, **kwargs) + + +if __name__ == '__main__': + + unittest.main() diff --git a/tests/test_coordinates.py b/tests/test_coordinates.py new file mode 100755 index 0000000..c09357e --- /dev/null +++ b/tests/test_coordinates.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 + +import unittest + + +file = '../examples/images/grid.jpg' +hint_img = '../examples/images/grid_hint.jpg' +hint_text = 'Select all images with an Orange' +checks = {'coordinatescaptcha': 1} + + +try: + from .abstract import AbstractTest + + file = file[3:] + hint_img = hint_img[3:] + +except ImportError: + from abstract import AbstractTest + + + + + + +class CoordinatesTest(AbstractTest): + + def test_file_param(self): + + sends = {'method': 'post', 'file': file, **checks} + return self.send_return(sends, self.solver.coordinates, file=file) + + + + def test_base64_param(self): + + b64 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + sends = { + 'method': 'base64', + 'body' : b64, + **checks, + } + + return self.send_return(sends, self.solver.coordinates, file=b64) + + + + def test_all_params(self): + + params = { + 'lang' : 'en', + 'hintImg' : hint_img, + 'hintText' : hint_text + } + + + sends = { + 'method' : 'post', + 'lang' : 'en', + 'files' : {'file': file,'imginstructions': hint_img}, + 'textinstructions' : hint_text, + **checks + } + + return self.send_return(sends, self.solver.coordinates, file=file, **params) + + + + def test_not_found(self): + + return self.invalid_file(self.solver.coordinates) + + + + + + + + + +if __name__ == '__main__': + + unittest.main() + diff --git a/tests/test_funcaptcha.py b/tests/test_funcaptcha.py new file mode 100755 index 0000000..9872598 --- /dev/null +++ b/tests/test_funcaptcha.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import unittest + +try: + from .abstract import AbstractTest +except ImportError: + from abstract import AbstractTest + + + +class FuncaptchaTest(AbstractTest): + + + def test_all_params(self): + + + params = { + 'sitekey' : '69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC', + 'url' : 'https://mysite.com/page/with/funcaptcha', + 'surl' : 'https://client-api.arkoselabs.com', + 'userAgent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36', + 'data' : {'anyKey' : 'anyStringValue'}, + } + + sends = { + 'method' : 'funcaptcha', + 'publickey' : '69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC', + 'pageurl' : 'https://mysite.com/page/with/funcaptcha', + 'surl' : 'https://client-api.arkoselabs.com', + 'userAgent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36', + 'data' : {'anyKey' : 'anyStringValue'}, + } + + return self.send_return(sends, self.solver.funcaptcha, **params) + + + + + +if __name__ == '__main__': + + unittest.main() + diff --git a/tests/test_geetest.py b/tests/test_geetest.py new file mode 100755 index 0000000..e62f807 --- /dev/null +++ b/tests/test_geetest.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import unittest + +try: + from .abstract import AbstractTest +except ImportError: + from abstract import AbstractTest + + + +class GeeTest(AbstractTest): + + + def test_all_params(self): + + + params = { + 'gt' : 'f2ae6cadcf7886856696502e1d55e00c', + 'apiServer' : 'api-na.geetest.com', + 'challenge' : '69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC', + 'url' : 'https://launches.endclothing.com/distil_r_captcha.html', } + + sends = { + 'method' : 'geetest', + 'gt' : 'f2ae6cadcf7886856696502e1d55e00c', + 'api_server' : 'api-na.geetest.com', + 'challenge' : '69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC', + 'pageurl' : 'https://launches.endclothing.com/distil_r_captcha.html', + } + + return self.send_return(sends, self.solver.geetest, **params) + + + + + +if __name__ == '__main__': + + unittest.main() + diff --git a/tests/test_geetest_v4.py b/tests/test_geetest_v4.py new file mode 100755 index 0000000..70c2df2 --- /dev/null +++ b/tests/test_geetest_v4.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +import unittest + +try: + from .abstract import AbstractTest +except ImportError: + from abstract import AbstractTest + + + +class GeeTest_V4(AbstractTest): + + + def test_all_params(self): + + + params = { + 'captcha_id': 'e392e1d7fd421dc63325744d5a2b9c73', + 'url' : 'https://mysite.com/page/with/geetest-v4', } + + sends = { + 'method' : 'geetest_v4', + 'captcha_id' : 'e392e1d7fd421dc63325744d5a2b9c73', + 'pageurl' : 'https://mysite.com/page/with/geetest-v4', + } + + return self.send_return(sends, self.solver.geetest_v4, **params) + + +if __name__ == '__main__': + + unittest.main() + diff --git a/tests/test_grid.py b/tests/test_grid.py new file mode 100755 index 0000000..1c7d80f --- /dev/null +++ b/tests/test_grid.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 + +import unittest + + +file = '../examples/images/grid.jpg' +hint_img = '../examples/images/grid_hint.jpg' +hint_text = 'Select all images with an Orange' + + +try: + from .abstract import AbstractTest + + file = file[3:] + hint_img = hint_img[3:] + +except ImportError: + from abstract import AbstractTest + + + + + + +class GridTest(AbstractTest): + + def test_file_param(self): + + sends = {'method': 'post', 'file': file, 'recaptcha': 1} + return self.send_return(sends, self.solver.grid, file=file) + + + + def test_base64_param(self): + + b64 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + sends = { + 'method' : 'base64', + 'body' : b64, + 'recaptcha' : 1 + } + + return self.send_return(sends, self.solver.grid, file=b64) + + + + def test_all_params(self): + + params = { + 'rows' : 3, + 'cols' : 3, + 'previousId' : 0, + 'canSkip' : 0, + 'lang' : 'en', + 'hintImg' : hint_img, + 'hintText' : hint_text + } + + + sends = { + 'method' : 'post', + 'recaptcha' : 1, + 'recaptcharows' : 3, + 'recaptchacols' : 3, + 'previousID' : 0, + 'can_no_answer' : 0, + 'lang' : 'en', + 'files' : {'file': file,'imginstructions': hint_img}, + 'textinstructions' : hint_text, + } + + return self.send_return(sends, self.solver.grid, file=file, **params) + + + + def test_not_found(self): + + return self.invalid_file(self.solver.grid) + + + + + + + + + +if __name__ == '__main__': + + unittest.main() + diff --git a/tests/test_hcaptcha.py b/tests/test_hcaptcha.py new file mode 100755 index 0000000..84f765e --- /dev/null +++ b/tests/test_hcaptcha.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +import unittest + +try: + from .abstract import AbstractTest +except ImportError: + from abstract import AbstractTest + + + +class HcaptchaTest(AbstractTest): + + + def test_all_params(self): + + + params = { + 'sitekey' : 'f1ab2cdefa3456789012345b6c78d90e', + 'url' : 'https://www.site.com/page/', + } + + sends = { + 'method' : 'hcaptcha', + 'sitekey' : 'f1ab2cdefa3456789012345b6c78d90e', + 'pageurl' : 'https://www.site.com/page/', + } + + return self.send_return(sends, self.solver.hcaptcha, **params) + + + + + +if __name__ == '__main__': + + unittest.main() + diff --git a/tests/test_keycaptcha.py b/tests/test_keycaptcha.py new file mode 100755 index 0000000..a31c88c --- /dev/null +++ b/tests/test_keycaptcha.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import unittest + +try: + from .abstract import AbstractTest +except ImportError: + from abstract import AbstractTest + + + +class KeyCaptchaTest(AbstractTest): + + + def test_all_params(self): + + + params = { + 's_s_c_user_id' : 10, + 's_s_c_session_id' : '493e52c37c10c2bcdf4a00cbc9ccd1e8', + 's_s_c_web_server_sign' : '9006dc725760858e4c0715b835472f22-pz-', + 's_s_c_web_server_sign2' : '2ca3abe86d90c6142d5571db98af6714', + 'url' : 'https://www.keycaptcha.ru/demo-magnetic/', + } + + sends = { + 'method' : 'keycaptcha', + 's_s_c_user_id' : 10, + 's_s_c_session_id' : '493e52c37c10c2bcdf4a00cbc9ccd1e8', + 's_s_c_web_server_sign' : '9006dc725760858e4c0715b835472f22-pz-', + 's_s_c_web_server_sign2' : '2ca3abe86d90c6142d5571db98af6714', + 'pageurl' : 'https://www.keycaptcha.ru/demo-magnetic/', + } + + return self.send_return(sends, self.solver.keycaptcha, **params) + + + + + +if __name__ == '__main__': + + unittest.main() + diff --git a/tests/test_normal.py b/tests/test_normal.py new file mode 100644 index 0000000..22f3688 --- /dev/null +++ b/tests/test_normal.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 + +import unittest + +file = '../examples/images/normal.jpg' +hint_img = '../examples/images/grid_hint.jpg' + + +try: + from .abstract import AbstractTest + + file = file[3:] + hint_img = hint_img[3:] + +except ImportError: + from abstract import AbstractTest + + + + +class NormalTest(AbstractTest): + + def test_file(self): + + sends = {'method': 'post', 'file': file} + return self.send_return(sends, self.solver.normal, file=file) + + + + # def test_file_params(self): + + # return self.test_send_return(self.method, self.file, method='post') + + + + def test_base64(self): + + b64 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + sends = { + 'method': 'base64', + 'body' : b64, + } + + return self.send_return(sends, self.solver.normal, file=b64) + + + + def test_all_params(self): + + + params = { + 'numeric' : 4, + 'minLen' : 4, + 'maxLen' : 20, + 'phrase' : 1, + 'caseSensitive' : 1, + 'calc' : 0, + 'lang' : 'en', + 'hintImg' : hint_img, + 'hintText' : 'Type red symbols only', + } + + + sends = { + 'files' : {'file': file,'imginstructions': hint_img}, + 'method' : 'post', + 'numeric' : 4, + 'min_len' : 4, + 'max_len' : 20, + 'phrase' : 1, + 'regsense' : 1, + 'calc' : 0, + 'lang' : 'en', + 'textinstructions' : 'Type red symbols only', + } + + # files = { + # 'file' : file, + # 'imginstructions' : hint, + # } + + return self.send_return(sends, self.solver.normal, file=file, **params) + + + + def test_not_found(self): + + return self.invalid_file(self.solver.normal) + + + + + + + + + + +if __name__ == '__main__': + + unittest.main() + diff --git a/tests/test_recaptcha.py b/tests/test_recaptcha.py new file mode 100755 index 0000000..47a9bc1 --- /dev/null +++ b/tests/test_recaptcha.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 + +import unittest + +try: + from .abstract import AbstractTest +except ImportError: + from abstract import AbstractTest + + + +class RecaptchaTest(AbstractTest): + + + def test_v2(self): + + params = { + 'sitekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', + 'url' : 'https://mysite.com/page/with/recaptcha', + 'invisible' : 1, + 'action' : 'verify', + } + + sends = { + 'method' : 'userrecaptcha', + 'googlekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', + 'pageurl' : 'https://mysite.com/page/with/recaptcha', + 'invisible': 1, + 'enterprise': 0, + 'action' : 'verify', + 'version' : 'v2', + } + + return self.send_return(sends, self.solver.recaptcha, **params) + + + def test_v3(self): + + params = { + 'sitekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', + 'url' : 'https://mysite.com/page/with/recaptcha', + 'invisible' : 1, + 'action' : 'verify', + 'version' : 'v3', + } + + sends = { + 'method' : 'userrecaptcha', + 'googlekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', + 'pageurl' : 'https://mysite.com/page/with/recaptcha', + 'invisible' : 1, + 'enterprise': 0, + 'action' : 'verify', + 'version' : 'v3', + } + + return self.send_return(sends, self.solver.recaptcha, **params) + + + +if __name__ == '__main__': + + unittest.main() + diff --git a/tests/test_text.py b/tests/test_text.py new file mode 100755 index 0000000..f1540ee --- /dev/null +++ b/tests/test_text.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +import unittest + +try: + from .abstract import AbstractTest +except ImportError: + from abstract import AbstractTest + + +class TextTest(AbstractTest): + def test_only_text(self): + + sends = { + 'method': 'post', + 'textcaptcha': 'Today is monday?', + } + + return self.send_return(sends, + self.solver.text, + text='Today is monday?') + + def test_all_params(self): + + params = { + 'text': 'Today is monday?', + 'lang': 'en', + } + + sends = { + 'method': 'post', + 'textcaptcha': 'Today is monday?', + 'lang': 'en', + } + + return self.send_return(sends, self.solver.text, **params) + + +if __name__ == '__main__': + + unittest.main() diff --git a/tests/test_turnstile.py b/tests/test_turnstile.py new file mode 100755 index 0000000..983a268 --- /dev/null +++ b/tests/test_turnstile.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +import unittest + +try: + from .abstract import AbstractTest +except ImportError: + from abstract import AbstractTest + +class TurnstileTest(AbstractTest): + + + def test_all_params(self): + + + params = { + 'sitekey' : '0x4AAAAAAAC3DHQFLr1GavRN', + 'url' : 'https://www.site.com/page/', + 'action' : 'foo', + 'data' : 'bar' + } + + sends = { + 'method' : 'turnstile', + 'sitekey' : '0x4AAAAAAAC3DHQFLr1GavRN', + 'action' : 'foo', + 'data' : 'bar', + 'pageurl' : 'https://www.site.com/page/', + } + + return self.send_return(sends, self.solver.turnstile, **params) + + +if __name__ == '__main__': + + unittest.main()