From 306f04466c34767968e41c92649f5d6129e810b3 Mon Sep 17 00:00:00 2001 From: Andrei Date: Thu, 10 Jan 2019 22:08:57 +0300 Subject: [PATCH] Add CustomCaptchaTask example and readme --- README.md | 10 ++- .../anticaptcha_customcaptcha_example.py | 82 +++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 anticaptcha_examples/anticaptcha_customcaptcha_example.py diff --git a/README.md b/README.md index 162fac9..416c448 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,15 @@ print(user_answer) Краткий пример: ```python - +from python3_anticaptcha import CustomCaptchaTask +# Введите ключ от сервиса AntiCaptcha, из своего аккаунта. Anticaptcha service key. +ANTICAPTCHA_KEY = "" +# ссылка на изображение +imageUrl = "https://files.anti-captcha.com/26/41f/c23/7c50ff19.jpg" +# минимальный пример использования модуля +my_custom_task = CustomCaptchaTask.CustomCaptchaTask(anticaptcha_key=ANTICAPTCHA_KEY).\ + captcha_handler(imageUrl=imageUrl) +print(my_custom_task) ``` 8.[Gee Test.](https://github.com/AndreiDrang/python3-anticaptcha/blob/master/anticaptcha_examples/anticaptcha_control_example.py) diff --git a/anticaptcha_examples/anticaptcha_customcaptcha_example.py b/anticaptcha_examples/anticaptcha_customcaptcha_example.py new file mode 100644 index 0000000..78c4863 --- /dev/null +++ b/anticaptcha_examples/anticaptcha_customcaptcha_example.py @@ -0,0 +1,82 @@ +import asyncio + +from python3_anticaptcha import CustomCaptchaTask + + +ANTICAPTCHA_KEY = "" + +# Пример с созданием CustomCaptcha + +# подробней - https://anticaptcha.atlassian.net/wiki/spaces/API/pages/241827850/CustomCaptchaTask +# ссылка на изображение +imageUrl = "https://files.anti-captcha.com/26/41f/c23/7c50ff19.jpg", +# кастомная форма для ответов пользователей +custom_form = '''[ + { + "label": "Number", + "labelHint": false, + "contentType": false, + "name": "license_plate", + "inputType": "text", + "inputOptions": { + "width": "100", + "placeHolder": "Enter a letters and number without spaces" + } + },{ + "label": "Car color", + "labelHint": "Select color of the car", + "name": "color", + "inputType": "select", + "inputOptions": [ + { + "value": "white", + "caption": "White color" + }, + { + "value": "black", + "caption": "Black color" + }, + { + "value": "grey", + "caption": "Grey color" + }, + { + "value": "blue", + "caption": "Blue color" + }, + { + "value": "red", + "caption": "Red color" + } + ] + } + ]''' + +my_custom_task = CustomCaptchaTask.CustomCaptchaTask(anticaptcha_key=ANTICAPTCHA_KEY, + assignment='Enter license plate number', + forms=custom_form).\ + captcha_handler(imageUrl=imageUrl) + + +print(my_custom_task) + + +# Асинхронный пример работы +async def run(): + try: + # Пример работы антикапчи с кастомной капчёй, асинхронно + result = CustomCaptchaTask.aioCustomCaptchaTask(anticaptcha_key=ANTICAPTCHA_KEY, + assignment='Enter license plate number', + forms=custom_form).\ + captcha_handler(imageUrl=imageUrl) + + print(result) + + except Exception as err: + print(err) + + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(run()) + loop.close()