Skip to content

Commit 10a275f

Browse files
authored
added yidun captcha for sync and async methods, examples and tests, and readme (#141)
1 parent 41e0aff commit 10a275f

10 files changed

Lines changed: 330 additions & 2 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Examples of API requests for different captcha types are available on the [Pytho
5050
- [CyberSiARA](#cybersiara)
5151
- [Altcha Captcha](#altcha-Captcha)
5252
- [Binance](#binance)
53+
- [Yidun](#yidun)
5354
- [Other methods](#other-methods)
5455
- [send / get\_result](#send--get_result)
5556
- [balance](#balance)
@@ -548,6 +549,17 @@ result = solver.binance(sitekey='register',
548549
validate_id='e20c622fa9384952832fc1c2a6b75c0a',)
549550
```
550551

552+
### Yidun
553+
554+
<sup>[API method description.](https://2captcha.com/2captcha-api#yidun)</sup>
555+
556+
Use this method to solve Yidun - NECaptcha. Returns a token.
557+
```python
558+
result = solver.yidun(sitekey='6b4d7e0c4f5a4c7db2f3a1e8c9d6f123',
559+
pageurl='https://mysite.com/page/with/yadun',
560+
)
561+
```
562+
551563
## Other methods
552564

553565
### send / get_result

examples/async/async_yidun.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import asyncio
2+
import sys
3+
import os
4+
5+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
6+
7+
from twocaptcha import AsyncTwoCaptcha
8+
9+
# in this example we store the API key inside environment variables that can be set like:
10+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
11+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
12+
# you can just set the API key directly to it's value like:
13+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
14+
15+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
16+
17+
solver = AsyncTwoCaptcha(api_key)
18+
19+
async def solve_captcha():
20+
try:
21+
return await solver.yidun(
22+
sitekey='6b4d7e0c4f5a4c7db2f3a1e8c9d6f123',
23+
pageurl='https://mysite.com/page/with/yidun',
24+
)
25+
26+
except Exception as e:
27+
sys.exit(e)
28+
29+
if __name__ == '__main__':
30+
result = asyncio.run(solve_captcha())
31+
sys.exit('result: ' + str(result))
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import asyncio
2+
import sys
3+
import os
4+
5+
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
6+
7+
from twocaptcha import AsyncTwoCaptcha
8+
9+
# in this example we store the API key inside environment variables that can be set like:
10+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
11+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
12+
# you can just set the API key directly to it's value like:
13+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
14+
15+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
16+
17+
config = {
18+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19+
'apiKey': api_key,
20+
'softId': 123,
21+
'defaultTimeout': 120,
22+
'recaptchaTimeout': 600,
23+
'pollingInterval': 10,
24+
}
25+
26+
solver = AsyncTwoCaptcha(**config)
27+
28+
async def solve_captcha():
29+
try:
30+
return await solver.yidun(
31+
sitekey='6b4d7e0c4f5a4c7db2f3a1e8c9d6f123',
32+
pageurl='https://mysite.com/page/with/yidun',
33+
yidun_get_lib='https://cstaticdun.126.net/load.min.js',
34+
yidun_api_server_subdomain='c.dun.163.com',
35+
challenge='8f7e4d2c1b9a6f5e3d4c7b8a9e0f123456789abcdef123456789abcdef1234',
36+
hcg='9a217825f3dcfac3d34e551e93819d610dec931e5e2a2236edf0e1f3f320c191',
37+
hct=1751469954806,
38+
useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
39+
"Chrome/148.0.0.0 Safari/537.36",
40+
# proxy={'type': 'HTTP',
41+
# 'uri': 'login:password@IP_address:PORT'}
42+
)
43+
except Exception as e:
44+
sys.exit(e)
45+
46+
if __name__ == '__main__':
47+
result = asyncio.run(solve_captcha())
48+
sys.exit('result: ' + str(result))

examples/sync/binance_options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
validate_id='e20c622fa9384952832fc1c2a6b75c0a',
3232
useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
3333
"Chrome/148.0.0.0 Safari/537.36",
34-
proxy={'type': 'HTTP',
35-
'uri': 'login:password@IP_address:PORT'}
34+
# proxy={'type': 'HTTP',
35+
# 'uri': 'login:password@IP_address:PORT'}
3636
)
3737

3838
except Exception as e:

examples/sync/yidun.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
5+
6+
from twocaptcha import TwoCaptcha
7+
8+
# in this example we store the API key inside environment variables that can be set like:
9+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11+
# you can just set the API key directly to it's value like:
12+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
13+
14+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15+
16+
solver = TwoCaptcha(api_key)
17+
18+
try:
19+
result = solver.yidun(
20+
sitekey='6b4d7e0c4f5a4c7db2f3a1e8c9d6f123',
21+
pageurl='https://mysite.com/page/with/yidun',
22+
)
23+
24+
except Exception as e:
25+
sys.exit(e)
26+
27+
else:
28+
sys.exit('result: ' + str(result))

examples/sync/yidun_options.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
5+
6+
from twocaptcha import TwoCaptcha
7+
8+
# in this example we store the API key inside environment variables that can be set like:
9+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11+
# you can just set the API key directly to it's value like:
12+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
13+
14+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15+
16+
config = {
17+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
18+
'apiKey': api_key,
19+
'softId': 123,
20+
'defaultTimeout': 120,
21+
'recaptchaTimeout': 600,
22+
'pollingInterval': 10,
23+
}
24+
25+
solver = TwoCaptcha(**config)
26+
27+
try:
28+
result = solver.yidun(
29+
sitekey='6b4d7e0c4f5a4c7db2f3a1e8c9d6f123',
30+
pageurl='https://mysite.com/page/with/yidun',
31+
yidun_get_lib='https://cstaticdun.126.net/load.min.js',
32+
yidun_api_server_subdomain='c.dun.163.com',
33+
challenge='8f7e4d2c1b9a6f5e3d4c7b8a9e0f123456789abcdef123456789abcdef1234',
34+
hcg='9a217825f3dcfac3d34e551e93819d610dec931e5e2a2236edf0e1f3f320c191',
35+
hct=1751469954806,
36+
useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
37+
"Chrome/148.0.0.0 Safari/537.36",
38+
# proxy={'type': 'HTTP',
39+
# 'uri': 'login:password@IP_address:PORT'}
40+
)
41+
42+
except Exception as e:
43+
sys.exit(e)
44+
45+
else:
46+
sys.exit('result: ' + str(result))

tests/async/test_async_yidun.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
5+
try:
6+
from .abstract_async import AsyncAbstractTest
7+
except ImportError:
8+
from abstract_async import AsyncAbstractTest
9+
10+
11+
class AsyncYidun(AsyncAbstractTest):
12+
def test_all_params(self):
13+
params = {
14+
'sitekey': '6b4d7e0c4f5a4c7db2f3a1e8c9d6f123',
15+
'pageurl': 'https://mysite.com/page/with/yadun',
16+
'yidun_get_lib': 'https://cstaticdun.126.net/load.min.js',
17+
'yidun_api_server_subdomain': 'c.dun.163.com',
18+
'challenge': '8f7e4d2c1b9a6f5e3d4c7b8a9e0f123456789abcdef123456789abcdef1234',
19+
'hcg': '9a217825f3dcfac3d34e551e93819d610dec931e5e2a2236edf0e1f3f320c191',
20+
'hct': 1751469954806,
21+
'useragent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
22+
"Chrome/148.0.0.0 Safari/537.36",
23+
'proxy': {'type': 'HTTP',
24+
'uri': 'login:password@IP_address:PORT'}
25+
}
26+
27+
sends = {
28+
'method': 'yidun',
29+
'sitekey': '6b4d7e0c4f5a4c7db2f3a1e8c9d6f123',
30+
'pageurl': 'https://mysite.com/page/with/yadun',
31+
'yidun_get_lib': 'https://cstaticdun.126.net/load.min.js',
32+
'yidun_api_server_subdomain': 'c.dun.163.com',
33+
'challenge': '8f7e4d2c1b9a6f5e3d4c7b8a9e0f123456789abcdef123456789abcdef1234',
34+
'hcg': '9a217825f3dcfac3d34e551e93819d610dec931e5e2a2236edf0e1f3f320c191',
35+
'hct': 1751469954806,
36+
'useragent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
37+
"Chrome/148.0.0.0 Safari/537.36",
38+
'proxytype': 'HTTP',
39+
'proxy': 'login:password@IP_address:PORT'
40+
}
41+
42+
self.send_return(sends, self.solver.yidun, **params)
43+
44+
45+
if __name__ == '__main__':
46+
unittest.main()

tests/sync/test_yidun.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
5+
try:
6+
from .abstract import AbstractTest
7+
except ImportError:
8+
from abstract import AbstractTest
9+
10+
11+
class CaptchaYidun(AbstractTest):
12+
13+
def test_all_params(self):
14+
params = {
15+
'sitekey': '6b4d7e0c4f5a4c7db2f3a1e8c9d6f123',
16+
'pageurl': 'https://mysite.com/page/with/yadun',
17+
'yidun_get_lib': 'https://cstaticdun.126.net/load.min.js',
18+
'yidun_api_server_subdomain': 'c.dun.163.com',
19+
'challenge': '8f7e4d2c1b9a6f5e3d4c7b8a9e0f123456789abcdef123456789abcdef1234',
20+
'hcg': '9a217825f3dcfac3d34e551e93819d610dec931e5e2a2236edf0e1f3f320c191',
21+
'hct': 1751469954806,
22+
'useragent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
23+
"Chrome/148.0.0.0 Safari/537.36",
24+
'proxy': {'type': 'HTTP',
25+
'uri': 'login:password@IP_address:PORT'}
26+
}
27+
28+
sends = {
29+
'method': 'yidun',
30+
'sitekey': '6b4d7e0c4f5a4c7db2f3a1e8c9d6f123',
31+
'pageurl': 'https://mysite.com/page/with/yadun',
32+
'yidun_get_lib': 'https://cstaticdun.126.net/load.min.js',
33+
'yidun_api_server_subdomain': 'c.dun.163.com',
34+
'challenge': '8f7e4d2c1b9a6f5e3d4c7b8a9e0f123456789abcdef123456789abcdef1234',
35+
'hcg': '9a217825f3dcfac3d34e551e93819d610dec931e5e2a2236edf0e1f3f320c191',
36+
'hct': 1751469954806,
37+
'useragent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
38+
"Chrome/148.0.0.0 Safari/537.36",
39+
'proxytype': 'HTTP',
40+
'proxy': 'login:password@IP_address:PORT'
41+
}
42+
43+
return self.send_return(sends, self.solver.yidun, **params)
44+
45+
46+
if __name__ == '__main__':
47+
unittest.main()
48+

twocaptcha/async_solver.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,38 @@ async def binance(self, pageurl, sitekey, validate_id, **kwargs):
10451045

10461046
return await result
10471047

1048+
async def yidun(self, sitekey, pageurl, **kwargs):
1049+
'''Wrapper for solving Yidun captcha.
1050+
1051+
Parameters
1052+
__________
1053+
1054+
sitekey : str
1055+
The 'sitekey' value found in the website source code.
1056+
pageurl : str
1057+
Full URL of the page containing the captcha.
1058+
yidun_get_lib : str, optional
1059+
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.
1060+
yidun_api_server_subdomain : str, optional
1061+
Yidun API server subdomain. Enter only the domain, without the https:// prefix.
1062+
challenge : str, optional
1063+
Usually sent in network requests during captcha initialization or display.
1064+
hcg : str, optional
1065+
Captcha hash used when forming the request. You can get this together with challenge.
1066+
hct : int, optional
1067+
Numeric timestamp or identifier used for Enterprise version validation.
1068+
useragent : str, optional
1069+
Browser User-Agent. We recommend sending a valid Windows browser string.
1070+
proxy : dict, optional
1071+
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
1072+
'''
1073+
result = self.solve(method="yidun",
1074+
pageurl=pageurl,
1075+
sitekey=sitekey,
1076+
**kwargs)
1077+
1078+
return await result
1079+
10481080
async def solve(self, timeout=0, polling_interval=0, **kwargs):
10491081
'''Sends captcha, receives result.
10501082

twocaptcha/solver.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ class TwoCaptcha():
109109
Wrapper for solving Yandex Smart.
110110
altcha(self, pageurl, challenge_url=None, challenge_json=None, **kwargs)
111111
Wrapper for solving Altcha Captcha.
112+
binance(self, pageurl, sitekey, validate_id, **kwargs)
113+
Wrapper for solving Binance captcha.
114+
yidun(self, sitekey, pageurl, **kwargs)
115+
Wrapper for solving Yidun captcha.
112116
solve(timeout=0, polling_interval=0, **kwargs)
113117
Sends CAPTCHA data and retrieves the result.
114118
balance()
@@ -1181,6 +1185,39 @@ def binance(self, pageurl, sitekey, validate_id, **kwargs):
11811185
**kwargs)
11821186

11831187
return result
1188+
1189+
def yidun(self, sitekey, pageurl, **kwargs):
1190+
'''Wrapper for solving Yidun captcha.
1191+
1192+
Parameters
1193+
__________
1194+
1195+
sitekey : str
1196+
The 'sitekey' value found in the website source code.
1197+
pageurl : str
1198+
Full URL of the page containing the captcha.
1199+
yidun_get_lib : str, optional
1200+
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.
1201+
yidun_api_server_subdomain : str, optional
1202+
Yidun API server subdomain. Enter only the domain, without the https:// prefix.
1203+
challenge : str, optional
1204+
Usually sent in network requests during captcha initialization or display.
1205+
hcg : str, optional
1206+
Captcha hash used when forming the request. You can get this together with challenge.
1207+
hct : int, optional
1208+
Numeric timestamp or identifier used for Enterprise version validation.
1209+
useragent : str, optional
1210+
Browser User-Agent. We recommend sending a valid Windows browser string.
1211+
proxy : dict, optional
1212+
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
1213+
'''
1214+
result = self.solve(
1215+
method="yidun",
1216+
pageurl=pageurl,
1217+
sitekey=sitekey,
1218+
**kwargs)
1219+
1220+
return result
11841221

11851222

11861223
def solve(self, timeout=0, polling_interval=0, **kwargs):

0 commit comments

Comments
 (0)