forked from simonfarah/tiktok-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
205 lines (164 loc) · 7.9 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
from os import system
from time import sleep
from colorama import init, Fore
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException
init(autoreset=True)
class Bot:
def __init__(self):
system("cls || clear")
self.printBanner()
print(Fore.YELLOW + "[~] Loading driver, please wait...")
try:
options = Options()
options.add_argument(
"--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"
)
self.driver = webdriver.Chrome(options=options)
print(Fore.GREEN + "[+] Driver loaded successfully")
print()
except Exception as e:
print(Fore.RED + f"[!] Error loading driver: {e}")
exit()
self.url = "https://zefoy.com"
self.captcha_xpath = "/html/body/div[5]/div[2]/form/div/div/div/div/button"
self.services = {
"followers": {
"title": "Followers",
"xpath": "/html/body/div[6]/div/div[2]/div/div/div[2]/div/button",
"status": None,
},
"hearts": {
"title": "Hearts",
"xpath": "/html/body/div[6]/div/div[2]/div/div/div[3]/div/button",
"status": None,
},
"comment_hearts": {
"title": "Comment Hearts",
"xpath": "/html/body/div[6]/div/div[2]/div/div/div[4]/div/button",
"status": None,
},
"views": {
"title": "Views",
"xpath": "/html/body/div[6]/div/div[2]/div/div/div[5]/div/button",
"status": None,
},
"shares": {
"title": "Shares",
"xpath": "/html/body/div[6]/div/div[2]/div/div/div[6]/div/button",
"status": None,
},
"favorites": {
"title": "Favorites",
"xpath": "/html/body/div[6]/div/div[2]/div/div/div[7]/div/button",
"status": None,
},
}
def start(self):
self.driver.get(self.url)
print(Fore.MAGENTA + "[!] In case of a 502 Bad Gateway error")
print(Fore.MAGENTA + "[!] please refresh the page")
print()
self.wait_for_xpath(self.captcha_xpath)
print(Fore.YELLOW + "[~] Please complete the captcha")
self.wait_for_xpath(self.services["followers"]["xpath"])
print(Fore.GREEN + "[+] Captcha completed successfully")
print()
self.driver.minimize_window()
self.check_services()
for index, service in enumerate(self.services):
title = self.services[service]["title"]
status = self.services[service]["status"]
print(Fore.BLUE + f"[{str(index + 1)}] {title}".ljust(20), status)
while True:
try:
choice = int(input(Fore.YELLOW + "[-] Choose an option : "))
except ValueError:
continue # This ensures the loop continues after a ValueError
if choice in range(1, 7):
break
self.select_service(choice)
def select_service(self, choice):
div = 6 + choice
service_key = list(self.services.keys())[choice - 1]
self.driver.find_element(By.XPATH, self.services[service_key]["xpath"]).click()
print()
video_url = input(Fore.MAGENTA + "[-] Video URL : ")
print()
self.start_service(div, video_url)
def start_service(self, div, video_url):
url_input_xpath = f"/html/body/div[{div}]/div/form/div/input"
search_btn_xpath = f"/html/body/div[{div}]/div/form/div/div/button"
send_btn_xpath = f"/html/body/div[{div}]/div/div/div[1]/div/form/button"
input_element = self.driver.find_element(By.XPATH, url_input_xpath)
input_element.clear()
input_element.send_keys(video_url)
while True:
# Click the search button
self.driver.find_element(By.XPATH, search_btn_xpath).click()
# Attempt to click the send button if it's present
try:
WebDriverWait(self.driver, 5).until(
EC.element_to_be_clickable((By.XPATH, send_btn_xpath))
).click()
except TimeoutException:
# If the send button isn't found, click the search button again
self.driver.find_element(By.XPATH, search_btn_xpath).click()
remaining_time = self.check_remaining_time(div)
if remaining_time is not None:
print(Fore.YELLOW + f"[~] Sleeping for {remaining_time} seconds")
sleep(remaining_time)
def check_remaining_time(self, div):
remaining_time_xpath = f"/html/body/div[{div}]/div/div/span[1]"
try:
element = self.driver.find_element(By.XPATH, remaining_time_xpath)
text = element.text
if "Please wait" in text:
minutes = text.split("Please wait ")[1].split(" ")[0]
seconds = text.split(" second")[0].split()[-1]
sleep_duration = int(minutes) * 60 + int(seconds) + 5
return sleep_duration
else:
return None
except NoSuchElementException:
return None
def check_services(self):
for service in self.services:
xpath = self.services[service]["xpath"]
try:
element = self.driver.find_element(By.XPATH, xpath)
if element.is_enabled():
self.services[service]["status"] = Fore.GREEN + "[WORKING]"
else:
self.services[service]["status"] = Fore.RED + "[OFFLINE]"
except NoSuchElementException:
self.services[service]["status"] = Fore.RED + "[OFFLINE]"
def wait_for_xpath(self, xpath):
while True:
try:
self.driver.find_element(By.XPATH, xpath)
return True
except NoSuchElementException:
sleep(1)
def printBanner(self):
print(
"""
████████╗██╗██╗░░██╗████████╗░█████╗░██╗░░██╗ ██████╗░░█████╗░████████╗
╚══██╔══╝██║██║░██╔╝╚══██╔══╝██╔══██╗██║░██╔╝ ██╔══██╗██╔══██╗╚══██╔══╝
░░░██║░░░██║█████═╝░░░░██║░░░██║░░██║█████═╝░ ██████╦╝██║░░██║░░░██║░░░
░░░██║░░░██║██╔═██╗░░░░██║░░░██║░░██║██╔═██╗░ ██╔══██╗██║░░██║░░░██║░░░
░░░██║░░░██║██║░╚██╗░░░██║░░░╚█████╔╝██║░╚██╗ ██████╦╝╚█████╔╝░░░██║░░░
░░░╚═╝░░░╚═╝╚═╝░░╚═╝░░░╚═╝░░░░╚════╝░╚═╝░░╚═╝ ╚═════╝░░╚════╝░░░░╚═╝░░░
Made by : Simon Farah
Github : https://github.com/simonfarah/tiktok-bot
------------------------------------------------------------------------
"""
)
if __name__ == "__main__":
bot = Bot()
bot.start()