diff --git a/README.md b/README.md index eb5ccf1..3f57704 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ Examples of API requests for different captcha types are available on the [Pytho - [CyberSiARA](#cybersiara) - [Altcha Captcha](#altcha-Captcha) - [Binance](#binance) + - [Yidun](#yidun) - [Other methods](#other-methods) - [send / get\_result](#send--get_result) - [balance](#balance) @@ -548,6 +549,17 @@ result = solver.binance(sitekey='register', validate_id='e20c622fa9384952832fc1c2a6b75c0a',) ``` +### Yidun + +[API method description.](https://2captcha.com/2captcha-api#yidun) + +Use this method to solve Yidun - NECaptcha. Returns a token. +```python +result = solver.yidun(sitekey='6b4d7e0c4f5a4c7db2f3a1e8c9d6f123', + pageurl='https://mysite.com/page/with/yadun', + ) +``` + ## Other methods ### send / get_result diff --git a/examples/async/async_yidun.py b/examples/async/async_yidun.py new file mode 100644 index 0000000..f17f96f --- /dev/null +++ b/examples/async/async_yidun.py @@ -0,0 +1,31 @@ +import asyncio +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from twocaptcha import AsyncTwoCaptcha + +# 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 = AsyncTwoCaptcha(api_key) + +async def solve_captcha(): + try: + return await solver.yidun( + sitekey='6b4d7e0c4f5a4c7db2f3a1e8c9d6f123', + pageurl='https://mysite.com/page/with/yidun', + ) + + except Exception as e: + sys.exit(e) + +if __name__ == '__main__': + result = asyncio.run(solve_captcha()) + sys.exit('result: ' + str(result)) \ No newline at end of file diff --git a/examples/async/async_yidun_options.py b/examples/async/async_yidun_options.py new file mode 100644 index 0000000..0accd6b --- /dev/null +++ b/examples/async/async_yidun_options.py @@ -0,0 +1,48 @@ +import asyncio +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))) + +from twocaptcha import AsyncTwoCaptcha + +# 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, + 'defaultTimeout': 120, + 'recaptchaTimeout': 600, + 'pollingInterval': 10, + } + +solver = AsyncTwoCaptcha(**config) + +async def solve_captcha(): + try: + return await solver.yidun( + sitekey='6b4d7e0c4f5a4c7db2f3a1e8c9d6f123', + pageurl='https://mysite.com/page/with/yidun', + yidun_get_lib='https://cstaticdun.126.net/load.min.js', + yidun_api_server_subdomain='c.dun.163.com', + challenge='8f7e4d2c1b9a6f5e3d4c7b8a9e0f123456789abcdef123456789abcdef1234', + hcg='9a217825f3dcfac3d34e551e93819d610dec931e5e2a2236edf0e1f3f320c191', + hct=1751469954806, + useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/148.0.0.0 Safari/537.36", + # proxy={'type': 'HTTP', + # 'uri': 'login:password@IP_address:PORT'} + ) + except Exception as e: + sys.exit(e) + +if __name__ == '__main__': + result = asyncio.run(solve_captcha()) + sys.exit('result: ' + str(result)) \ No newline at end of file diff --git a/examples/sync/binance_options.py b/examples/sync/binance_options.py index 736092c..6747752 100644 --- a/examples/sync/binance_options.py +++ b/examples/sync/binance_options.py @@ -31,8 +31,8 @@ validate_id='e20c622fa9384952832fc1c2a6b75c0a', useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/148.0.0.0 Safari/537.36", - proxy={'type': 'HTTP', - 'uri': 'login:password@IP_address:PORT'} + # proxy={'type': 'HTTP', + # 'uri': 'login:password@IP_address:PORT'} ) except Exception as e: diff --git a/examples/sync/yidun.py b/examples/sync/yidun.py new file mode 100644 index 0000000..b30f34b --- /dev/null +++ b/examples/sync/yidun.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.yidun( + sitekey='6b4d7e0c4f5a4c7db2f3a1e8c9d6f123', + pageurl='https://mysite.com/page/with/yidun', + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) \ No newline at end of file diff --git a/examples/sync/yidun_options.py b/examples/sync/yidun_options.py new file mode 100644 index 0000000..c0cb6b1 --- /dev/null +++ b/examples/sync/yidun_options.py @@ -0,0 +1,46 @@ +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, + 'defaultTimeout': 120, + 'recaptchaTimeout': 600, + 'pollingInterval': 10, + } + +solver = TwoCaptcha(**config) + +try: + result = solver.yidun( + sitekey='6b4d7e0c4f5a4c7db2f3a1e8c9d6f123', + pageurl='https://mysite.com/page/with/yidun', + yidun_get_lib='https://cstaticdun.126.net/load.min.js', + yidun_api_server_subdomain='c.dun.163.com', + challenge='8f7e4d2c1b9a6f5e3d4c7b8a9e0f123456789abcdef123456789abcdef1234', + hcg='9a217825f3dcfac3d34e551e93819d610dec931e5e2a2236edf0e1f3f320c191', + hct=1751469954806, + useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/148.0.0.0 Safari/537.36", + # proxy={'type': 'HTTP', + # '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/tests/async/test_async_yidun.py b/tests/async/test_async_yidun.py new file mode 100644 index 0000000..19cc2f6 --- /dev/null +++ b/tests/async/test_async_yidun.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 + +import unittest + +try: + from .abstract_async import AsyncAbstractTest +except ImportError: + from abstract_async import AsyncAbstractTest + + +class AsyncYidun(AsyncAbstractTest): + def test_all_params(self): + params = { + 'sitekey': '6b4d7e0c4f5a4c7db2f3a1e8c9d6f123', + 'pageurl': 'https://mysite.com/page/with/yadun', + 'yidun_get_lib': 'https://cstaticdun.126.net/load.min.js', + 'yidun_api_server_subdomain': 'c.dun.163.com', + 'challenge': '8f7e4d2c1b9a6f5e3d4c7b8a9e0f123456789abcdef123456789abcdef1234', + 'hcg': '9a217825f3dcfac3d34e551e93819d610dec931e5e2a2236edf0e1f3f320c191', + 'hct': 1751469954806, + 'useragent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/148.0.0.0 Safari/537.36", + 'proxy': {'type': 'HTTP', + 'uri': 'login:password@IP_address:PORT'} + } + + sends = { + 'method': 'yidun', + 'sitekey': '6b4d7e0c4f5a4c7db2f3a1e8c9d6f123', + 'pageurl': 'https://mysite.com/page/with/yadun', + 'yidun_get_lib': 'https://cstaticdun.126.net/load.min.js', + 'yidun_api_server_subdomain': 'c.dun.163.com', + 'challenge': '8f7e4d2c1b9a6f5e3d4c7b8a9e0f123456789abcdef123456789abcdef1234', + 'hcg': '9a217825f3dcfac3d34e551e93819d610dec931e5e2a2236edf0e1f3f320c191', + 'hct': 1751469954806, + 'useragent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/148.0.0.0 Safari/537.36", + 'proxytype': 'HTTP', + 'proxy': 'login:password@IP_address:PORT' + } + + self.send_return(sends, self.solver.yidun, **params) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/sync/test_yidun.py b/tests/sync/test_yidun.py new file mode 100644 index 0000000..726ebdb --- /dev/null +++ b/tests/sync/test_yidun.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +import unittest + +try: + from .abstract import AbstractTest +except ImportError: + from abstract import AbstractTest + + +class CaptchaYidun(AbstractTest): + + def test_all_params(self): + params = { + 'sitekey': '6b4d7e0c4f5a4c7db2f3a1e8c9d6f123', + 'pageurl': 'https://mysite.com/page/with/yadun', + 'yidun_get_lib': 'https://cstaticdun.126.net/load.min.js', + 'yidun_api_server_subdomain': 'c.dun.163.com', + 'challenge': '8f7e4d2c1b9a6f5e3d4c7b8a9e0f123456789abcdef123456789abcdef1234', + 'hcg': '9a217825f3dcfac3d34e551e93819d610dec931e5e2a2236edf0e1f3f320c191', + 'hct': 1751469954806, + 'useragent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/148.0.0.0 Safari/537.36", + 'proxy': {'type': 'HTTP', + 'uri': 'login:password@IP_address:PORT'} + } + + sends = { + 'method': 'yidun', + 'sitekey': '6b4d7e0c4f5a4c7db2f3a1e8c9d6f123', + 'pageurl': 'https://mysite.com/page/with/yadun', + 'yidun_get_lib': 'https://cstaticdun.126.net/load.min.js', + 'yidun_api_server_subdomain': 'c.dun.163.com', + 'challenge': '8f7e4d2c1b9a6f5e3d4c7b8a9e0f123456789abcdef123456789abcdef1234', + 'hcg': '9a217825f3dcfac3d34e551e93819d610dec931e5e2a2236edf0e1f3f320c191', + 'hct': 1751469954806, + 'useragent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/148.0.0.0 Safari/537.36", + 'proxytype': 'HTTP', + 'proxy': 'login:password@IP_address:PORT' + } + + return self.send_return(sends, self.solver.yidun, **params) + + +if __name__ == '__main__': + unittest.main() + diff --git a/twocaptcha/async_solver.py b/twocaptcha/async_solver.py index 4735a6a..bb2763c 100644 --- a/twocaptcha/async_solver.py +++ b/twocaptcha/async_solver.py @@ -1045,6 +1045,38 @@ async def binance(self, pageurl, sitekey, validate_id, **kwargs): return await result + async def yidun(self, sitekey, pageurl, **kwargs): + '''Wrapper for solving Yidun captcha. + + Parameters + __________ + + sitekey : str + The 'sitekey' value found in the website source code. + pageurl : str + Full URL of the page containing the captcha. + yidun_get_lib : str, optional + Path to the JavaScript file that loads the captcha on the page. Important: use the full URL (https://...). Recommended if the site includes challenge, hcg, or hct fields. + yidun_api_server_subdomain : str, optional + Yidun API server subdomain. Enter only the domain, without the https:// prefix. + challenge : str, optional + Usually sent in network requests during captcha initialization or display. + hcg : str, optional + Captcha hash used when forming the request. You can get this together with challenge. + hct : int, optional + Numeric timestamp or identifier used for Enterprise version validation. + useragent : str, optional + Browser User-Agent. We recommend sending a valid Windows browser string. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + result = self.solve(method="yidun", + pageurl=pageurl, + sitekey=sitekey, + **kwargs) + + return await result + async def solve(self, timeout=0, polling_interval=0, **kwargs): '''Sends captcha, receives result. diff --git a/twocaptcha/solver.py b/twocaptcha/solver.py index a0857fe..88df586 100755 --- a/twocaptcha/solver.py +++ b/twocaptcha/solver.py @@ -109,6 +109,10 @@ class TwoCaptcha(): Wrapper for solving Yandex Smart. altcha(self, pageurl, challenge_url=None, challenge_json=None, **kwargs) Wrapper for solving Altcha Captcha. + binance(self, pageurl, sitekey, validate_id, **kwargs) + Wrapper for solving Binance captcha. + yidun(self, sitekey, pageurl, **kwargs) + Wrapper for solving Yidun captcha. solve(timeout=0, polling_interval=0, **kwargs) Sends CAPTCHA data and retrieves the result. balance() @@ -1181,6 +1185,39 @@ def binance(self, pageurl, sitekey, validate_id, **kwargs): **kwargs) return result + + def yidun(self, sitekey, pageurl, **kwargs): + '''Wrapper for solving Yidun captcha. + + Parameters + __________ + + sitekey : str + The 'sitekey' value found in the website source code. + pageurl : str + Full URL of the page containing the captcha. + yidun_get_lib : str, optional + Path to the JavaScript file that loads the captcha on the page. Important: use the full URL (https://...). Recommended if the site includes challenge, hcg, or hct fields. + yidun_api_server_subdomain : str, optional + Yidun API server subdomain. Enter only the domain, without the https:// prefix. + challenge : str, optional + Usually sent in network requests during captcha initialization or display. + hcg : str, optional + Captcha hash used when forming the request. You can get this together with challenge. + hct : int, optional + Numeric timestamp or identifier used for Enterprise version validation. + useragent : str, optional + Browser User-Agent. We recommend sending a valid Windows browser string. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + result = self.solve( + method="yidun", + pageurl=pageurl, + sitekey=sitekey, + **kwargs) + + return result def solve(self, timeout=0, polling_interval=0, **kwargs):