From c6357039eac4fe5f2fe54852c6c5b2820a580adb Mon Sep 17 00:00:00 2001 From: sepera_okeq <54331959+Sepera-okeq@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:43:24 +0000 Subject: [PATCH 1/6] feat: yandex smart --- twocaptcha/solver.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/twocaptcha/solver.py b/twocaptcha/solver.py index dbf4378..af7b6b5 100755 --- a/twocaptcha/solver.py +++ b/twocaptcha/solver.py @@ -856,6 +856,33 @@ def cybersiara(self, master_url_id, pageurl, userAgent, **kwargs): **kwargs) return result + def yandex_smart(self, sitekey, url, **kwargs): + '''Wrapper for solving Yandex Smart. + + Parameters + __________ + sitekey : str + The value of data-sitekey attribute of captcha's div element on page. + url : str + Full URL of the page where you solve the captcha. + softId : int, optional + ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of + spendings of their software users. + 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://2captcha.com/2captcha-api#pingback. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + userAgent: str, optional + User-Agent of the browser that will be used by the employee when loading the captcha. + ''' + + result = self.solve(sitekey=sitekey, + url=url, + method='yandex', + **kwargs) + return result + def solve(self, timeout=0, polling_interval=0, **kwargs): '''Sends captcha, receives result. From 588680e1a37a2d1148f107f4b8096d09011092eb Mon Sep 17 00:00:00 2001 From: sepera_okeq <54331959+Sepera-okeq@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:45:26 +0000 Subject: [PATCH 2/6] docs: new support method Yandex Smart --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 59a1293..d84ec76 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Examples of API requests for different captcha types are available on the [Pytho - [FunCaptcha](#funcaptcha) - [GeeTest](#geetest) - [GeeTest v4](#geetest-v4) + - [Yandex Smart](#yandex-smart) - [Lemin Cropped Captcha](#lemin-cropped-captcha) - [Cloudflare Turnstile](#cloudflare-turnstile) - [Amazon WAF](#amazon-waf) @@ -240,6 +241,18 @@ result = solver.lemin(captcha_id='CROPPED_1abcd2f_a1234b567c890d12ef3a456bc78d90 ``` +### Yandex Smart + +[API method description.](https://2captcha.com/2captcha-api#yandex-smart) + +Use this method to solve Yandex Smart Captcha. Returns JSON with the token. +```python +result = solver.yandex_smart(sitekey='0x1AAAAh45AAAAkg0s2VIOD34y5hy4h4h', + url='http://mysite.com/', + softId=123, + proxy={'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}, + 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') +``` ### Cloudflare Turnstile From 9fe65b5c742656afa953f0070a7e4f9f6599caf8 Mon Sep 17 00:00:00 2001 From: sepera_okeq <54331959+Sepera-okeq@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:49:50 +0000 Subject: [PATCH 3/6] fix: add tests yandex smart captcha --- tests/test_yandex_smart_captcha.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/test_yandex_smart_captcha.py diff --git a/tests/test_yandex_smart_captcha.py b/tests/test_yandex_smart_captcha.py new file mode 100644 index 0000000..3042611 --- /dev/null +++ b/tests/test_yandex_smart_captcha.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +import unittest + +try: + from .abstract import AbstractTest +except ImportError: + from abstract import AbstractTest + + +class YandexSmartCaptchaTest(AbstractTest): + + def test_all_params(self): + params = { + 'sitekey': 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxjtNB9', + 'url': 'https://captcha-api.yandex.ru/demo', + } + + sends = { + 'method': 'yandex', + 'sitekey': 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxjtNB9', + 'pageurl': 'https://captcha-api.yandex.ru/demo', + } + + return self.send_return(sends, self.solver.yandex_smart, **params) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From b28efc06ad83946266844476535e01ef69d89b4b Mon Sep 17 00:00:00 2001 From: Maxim S Date: Thu, 12 Dec 2024 14:10:21 +0100 Subject: [PATCH 4/6] Added examples yandex_smart Signed-off-by: Maxim S --- examples/yandex_smart.py | 28 ++++++++++++++++++++ examples/yandex_smart_options.py | 42 ++++++++++++++++++++++++++++++ tests/test_yandex_smart_captcha.py | 8 +++--- 3 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 examples/yandex_smart.py create mode 100644 examples/yandex_smart_options.py diff --git a/examples/yandex_smart.py b/examples/yandex_smart.py new file mode 100644 index 0000000..a8eb4c4 --- /dev/null +++ b/examples/yandex_smart.py @@ -0,0 +1,28 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from twocaptcha import TwoCaptcha + +# in this example we store the API key inside environment variables that can be set like: +# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS +# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows +# you can just set the API key directly to it's value like: +# api_key="1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY') + +solver = TwoCaptcha(api_key) + +try: + result = solver.yandex_smart( + sitekey="FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxK4OoR", + url="https://www.site.com/page/" + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) \ No newline at end of file diff --git a/examples/yandex_smart_options.py b/examples/yandex_smart_options.py new file mode 100644 index 0000000..3a8b548 --- /dev/null +++ b/examples/yandex_smart_options.py @@ -0,0 +1,42 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from twocaptcha import TwoCaptcha + +# in this example we store the API key inside environment variables that can be set like: +# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS +# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows +# you can just set the API key directly to it's value like: +# api_key="1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY') + + +config = { + 'server': '2captcha.com', # can be also set to 'rucaptcha.com' + 'apiKey': api_key, + 'softId': 123, + # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer + 'defaultTimeout': 120, + 'recaptchaTimeout': 600, + 'pollingInterval': 10, + } + +solver = TwoCaptcha(**config) + +try: + result = solver.yandex_smart(sitekey="FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxK4OoR", + url="https://www.site.com/page/", + # 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/tests/test_yandex_smart_captcha.py b/tests/test_yandex_smart_captcha.py index 3042611..e322191 100644 --- a/tests/test_yandex_smart_captcha.py +++ b/tests/test_yandex_smart_captcha.py @@ -12,14 +12,14 @@ class YandexSmartCaptchaTest(AbstractTest): def test_all_params(self): params = { - 'sitekey': 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxjtNB9', - 'url': 'https://captcha-api.yandex.ru/demo', + 'sitekey': 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdPpL4O', + 'url': 'https://www.site.com/page/', } sends = { 'method': 'yandex', - 'sitekey': 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxjtNB9', - 'pageurl': 'https://captcha-api.yandex.ru/demo', + 'sitekey': 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdPpL4O', + 'pageurl': 'https://www.site.com/page/', } return self.send_return(sends, self.solver.yandex_smart, **params) From 18090c2b5e0a48c6d2e50129cf726d3319a038af Mon Sep 17 00:00:00 2001 From: Maxim S Date: Thu, 12 Dec 2024 14:31:46 +0100 Subject: [PATCH 5/6] update README.md Signed-off-by: Maxim S --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index d84ec76..1df22f9 100644 --- a/README.md +++ b/README.md @@ -243,8 +243,6 @@ result = solver.lemin(captcha_id='CROPPED_1abcd2f_a1234b567c890d12ef3a456bc78d90 ### Yandex Smart -[API method description.](https://2captcha.com/2captcha-api#yandex-smart) - Use this method to solve Yandex Smart Captcha. Returns JSON with the token. ```python result = solver.yandex_smart(sitekey='0x1AAAAh45AAAAkg0s2VIOD34y5hy4h4h', From 37ecd8ec944dbfa3a1cd8876ee3a126f7d713dd0 Mon Sep 17 00:00:00 2001 From: Maxim S Date: Thu, 12 Dec 2024 14:43:36 +0100 Subject: [PATCH 6/6] update README.md Signed-off-by: Maxim S --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 1df22f9..96907cc 100644 --- a/README.md +++ b/README.md @@ -247,7 +247,6 @@ Use this method to solve Yandex Smart Captcha. Returns JSON with the token. ```python result = solver.yandex_smart(sitekey='0x1AAAAh45AAAAkg0s2VIOD34y5hy4h4h', url='http://mysite.com/', - softId=123, proxy={'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}, 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') ```