Client library for solve captchas with Anticaptcha.com support.
Project description
Client library for solve captchas with Anticaptcha.com support. The library supports both Python 2.7 and Python 3.
The library is cyclically and automatically tested for proper operation. We are constantly making the best efforts for its effective operation.
In case of any problems with integration - read the documentation, create an issue, use Gitter or contact privately.
Getting Started
Install as standard Python package using:
pip install python-anticaptcha
Usage
To use this library do you need Anticaptcha.com API key.
Solve recaptcha
Example snippet for Recaptcha:
from python_anticaptcha import AnticaptchaClient, NoCaptchaTaskProxylessTask
api_key = '174faff8fbc769e94a5862391ecfd010'
site_key = '6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-' # grab from site
url = 'https://www.google.com/recaptcha/api2/demo'
client = AnticaptchaClient(api_key)
task = NoCaptchaTaskProxylessTask(url, site_key)
job = client.createTask(task)
job.join()
print job.get_solution_response()
The full integration example is available in file examples/recaptcha.py.
If you only process few page many times to increase reliability, you can specify whether the captcha is visible or not. This parameter is not required, as is the system detects invisible sitekeys automatically, and needs several recursive measures for automated training and analysis. For provide that pass is_invisible parameter to NoCaptchaTaskProxylessTask or NoCaptchaTask eg.:
from python_anticaptcha import AnticaptchaClient, NoCaptchaTaskProxylessTask
api_key = '174faff8fbc769e94a5862391ecfd010'
site_key = '6Lc-0DYUAAAAAOPM3RGobCfKjIE5STmzvZfHbbNx' # grab from site
url = 'https://losangeles.craigslist.org/lac/kid/d/housekeeper-sitting-pet-care/6720136191.html'
client = AnticaptchaClient(api_key)
task = NoCaptchaTaskProxylessTask(url, site_key, is_invisible=True)
job = client.createTask(task)
job.join()
print job.get_solution_response()
Solve text captcha
Example snippet for text captcha:
from python_anticaptcha import AnticaptchaClient, ImageToTextTask
api_key = '174faff8fbc769e94a5862391ecfd010'
captcha_fp = open('examples/captcha_ms.jpeg', 'rb')
client = AnticaptchaClient(api_key)
task = ImageToTextTask(captcha_fp)
job = client.createTask(task)
job.join()
print job.get_captcha_text()
Solve funcaptcha
Example snippet for funcaptcha:
from python_anticaptcha import AnticaptchaClient, FunCaptchaTask, Proxy
UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 ' \
'(KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'
api_key = '174faff8fbc769e94a5862391ecfd010'
site_key = 'DE0B0BB7-1EE4-4D70-1853-31B835D4506B' # grab from site
url = 'https://www.google.com/recaptcha/api2/demo'
proxy = Proxy.parse_url("socks5://login:password@123.123.123.123")
client = AnticaptchaClient(api_key)
task = FunCaptchaTask(url, site_key, proxy=proxy, user_agent=user_agent)
job = client.createTask(task)
job.join()
print job.get_token_response()
Report incorrect image
Example snippet for reporting an incorrect image task:
from python_anticaptcha import AnticaptchaClient, ImageToTextTask
api_key = '174faff8fbc769e94a5862391ecfd010'
captcha_fp = open('examples/captcha_ms.jpeg', 'rb')
client = AnticaptchaClient(api_key)
task = ImageToTextTask(captcha_fp)
job = client.createTask(task)
job.join()
print job.get_captcha_text()
job.report_incorrect()
Setup proxy
The library is not responsible for managing the proxy server. However, we point to the possibility of simply launching such a server by:
pip install mitmproxy
mitmweb -p 9190 -b 0.0.0.0 --ignore '.' --socks
Next to in your application use something like:
proxy = Proxy.parse_url("socks5://123.123.123.123:9190")
We recommend entering IP-based access control for incoming addresses to proxy. IP address required by Anticaptcha.com is:
69.65.41.21
209.212.146.168
Error handling
In the event of an application error, the AnticaptchaException exception is thrown. To handle the exception, do the following:
from python_anticaptcha import AnticatpchaException, ImageToTextTask
try:
# any actions
except AnticatpchaException as e:
if e.error_code == 'ERROR_ZERO_BALANCE':
notify_about_no_funds(e.error_id, e.error_code, e.error_description)
else:
raise
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python-anticaptcha-1.0.0.tar.gz
.
File metadata
- Download URL: python-anticaptcha-1.0.0.tar.gz
- Upload date:
- Size: 42.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 058a9e3ca5dbdcaa98108c8b5181404cb4ffdba5261162a4301d60f985c63710 |
|
MD5 | ad007df801f1c88e20a6af73b6043130 |
|
BLAKE2b-256 | c630d47e8e34b6847ea98515b6f08fce503ae5109828381f4daaefc624fcb163 |
File details
Details for the file python_anticaptcha-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: python_anticaptcha-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12e47cc1f27a0ab2080975a9c8b2554219570dad1d8feb0b9911078b17767f27 |
|
MD5 | 569da9aff92f3411893047ed3aaa4ffe |
|
BLAKE2b-256 | 09405489582e7aff47ca9e6d7f664b55a7e5e9cbf2a0958366b5ef4eab098a26 |