· 5 years ago · Jan 28, 2021, 11:30 AM
1import time
2import random
3import vk_api
4import requests
5from PIL import Image
6import urllib.request
7
8def captcha(url):
9 urllib.request.urlretrieve(url, "./Captcha/captcha.jfif")
10 Image.open("./Captcha/captcha.jfif").save("./Captcha/captcha.png")
11
12 key = "токен рукапчи"
13 data = {"key" : key}
14 files = {"file": open("./Captcha/captcha.png", "rb")}
15
16 response = requests.post("https://rucaptcha.com/in.php", data=data, files=files)
17 print("Отправка запроса на решение капчи...")
18 if(response.status_code == 200):
19 print("Запрос отправлен успешно! Будем запрашивать ответ через 5 секунд")
20 id = str(response.text).split('|')[1]
21 while True:
22 time.sleep(5)
23 print("Запрос ответа...")
24 response = requests.get("https://rucaptcha.com/res.php?key=" + key + "&action=get&id=" + id)
25 if(str(response.text).split('|')[0] == "OK"):
26 print("Капча готова: " + str(response.text).split('|')[1])
27 return str(response.text).split('|')[1]
28 elif(str(response.text) == "CAPCHA_NOT_READY"):
29 print("Капча еще не готова, повторим запрос через 5 сек...")
30 else:
31 print("Неизвестный ответ: " + str(response.text))
32 if(input("Продолжить запросы? (y/n) ").upper() == "Y"):
33 print("Повторим запрос через 5 сек...")
34 continue
35 else:
36 print("Отменено пользователем.")
37 return -1
38
39def add_firend_captcha(id, sid, key):
40 api.method('friends.add', {'user_id': id, 'captcha_sid': sid, 'captcha_key':key})
41
42TOKEN = input('Введите токен>')
43
44FRIENDS_COUNT = int(input('Сколько накрутить друзей>'))
45
46DELAY = 5
47
48GROUPS_IDS = (-53294903,-51445749)
49
50ADDED_USERS = []
51
52RUCAPTCHA = True
53
54api = vk_api.VkApi(token=TOKEN)
55
56while FRIENDS_COUNT:
57 time.sleep(DELAY)
58 try:
59 user_post = api.method('wall.get', {'owner_id':random.choice(GROUPS_IDS), 'count':1})
60 user_id = user_post["items"][0]["from_id"]
61 if user_id not in ADDED_USERS:
62
63 api.method('friends.add', {'user_id':user_id})
64
65 FRIENDS_COUNT -= 1
66
67 ADDED_USERS.append(user_id)
68
69 if FRIENDS_COUNT != 0:
70 print(f'Добавил в друзья vk.com/id{user_id}\nОсталось накрутить {FRIENDS_COUNT}')
71 elif FRIENDS_COUNT == 0:
72 print('Накрутка завершена!')
73 except vk_api.exceptions.Captcha as captcha:
74 if RUCAPTCHA:
75 try:
76 captcha_compl = captcha(captcha.get_url())
77 if(captcha_compl == -1):
78 print("Отмена в связи с ошибкой капчи!")
79 break
80 else:
81 try:
82 add_firend_captcha(user_id, captcha.sid, captcha_compl)
83 except:
84 print("Попалась неправильная капча")
85 except:
86 pass
87 if not RUCAPTCHA:
88 try:
89 captcha.sid
90 print(f'Появилась капча - {captcha.get_url()}')
91 captcha_key = input('Введите капчу:')
92 captcha.try_again(captcha_key)
93 except:
94 pass
95 except vk_api.exceptions.VkApiError:
96 pass