Skip to content

Commit b28efc0

Browse files
committed
Added examples yandex_smart
Signed-off-by: Maxim S <[email protected]>
1 parent 9fe65b5 commit b28efc0

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

examples/yandex_smart.py

+28
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.yandex_smart(
20+
sitekey="FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxK4OoR",
21+
url="https://www.site.com/page/"
22+
)
23+
24+
except Exception as e:
25+
sys.exit(e)
26+
27+
else:
28+
sys.exit('result: ' + str(result))

examples/yandex_smart_options.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
17+
config = {
18+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19+
'apiKey': api_key,
20+
'softId': 123,
21+
# 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22+
'defaultTimeout': 120,
23+
'recaptchaTimeout': 600,
24+
'pollingInterval': 10,
25+
}
26+
27+
solver = TwoCaptcha(**config)
28+
29+
try:
30+
result = solver.yandex_smart(sitekey="FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxK4OoR",
31+
url="https://www.site.com/page/",
32+
# proxy={
33+
# 'type': 'HTTPS',
34+
# 'uri': 'login:password@IP_address:PORT'
35+
# }
36+
)
37+
38+
except Exception as e:
39+
sys.exit(e)
40+
41+
else:
42+
sys.exit('result: ' + str(result))

tests/test_yandex_smart_captcha.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ class YandexSmartCaptchaTest(AbstractTest):
1212

1313
def test_all_params(self):
1414
params = {
15-
'sitekey': 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxjtNB9',
16-
'url': 'https://captcha-api.yandex.ru/demo',
15+
'sitekey': 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdPpL4O',
16+
'url': 'https://www.site.com/page/',
1717
}
1818

1919
sends = {
2020
'method': 'yandex',
21-
'sitekey': 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxjtNB9',
22-
'pageurl': 'https://captcha-api.yandex.ru/demo',
21+
'sitekey': 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdPpL4O',
22+
'pageurl': 'https://www.site.com/page/',
2323
}
2424

2525
return self.send_return(sends, self.solver.yandex_smart, **params)

0 commit comments

Comments
 (0)