Skip to content

Add Yandex Smart Solver #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -240,6 +241,18 @@ result = solver.lemin(captcha_id='CROPPED_1abcd2f_a1234b567c890d12ef3a456bc78d90

```

### Yandex Smart

<sup>[API method description.](https://2captcha.com/2captcha-api#yandex-smart)</sup>

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

Expand Down
29 changes: 29 additions & 0 deletions tests/test_yandex_smart_captcha.py
Original file line number Diff line number Diff line change
@@ -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()
27 changes: 27 additions & 0 deletions twocaptcha/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down