M
M
Matthew Stafford2019-09-30 13:00:45
Python
Matthew Stafford, 2019-09-30 13:00:45

How to attach anti-captcha module to vk_api?

For example, there is a code like this

import random
import requests
import vk_api

token = 'TOKEN'  # Токен пользователя
delay = '5' # Задержка в секундах

vk_session = vk_api.VkApi(token=token)

from vk_api.longpoll import VkLongPoll, VkEventType
longpoll = VkLongPoll(vk_session)
vk = vk_session.get_api()
for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:		
        if 'Привет:' in event.text:
            time.sleep(int(delay))
            if event.from_user:
                    vk.messages.send(
                        user_id = event.user_id,
                        random_id = random.randint(111111,999999999),
                        message = 'Привет'
                    )

How can I get a captcha and solve it using anti-captcha, and then send it to VK? Or how should it be done in general?
###UPD:
I changed the code a little
try:
  vk.messages.send(
    user_id = event.user_id,
    random_id = random.randint(111111,999999999),
    message = 'Привет'
  )
except vk_api.Captcha as e:
  print(e.url) #картинка с капчей
  print(e.sid) #sid капчи для отправки ответа

If I get a captcha, then I get its sid and url. How can I now send it to anticaptcha, get a solution and send it to VK?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Antonio Solo, 2019-09-30
@solotony

>>

I can send it to anti-captcha, get a solution

which service exactly? it has an API
repeat the request specifying captcha_key captcha_sid

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question