-
Notifications
You must be signed in to change notification settings - Fork 0
/
instagram-bot-enhanced.py
283 lines (270 loc) · 13.2 KB
/
instagram-bot-enhanced.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
import multiprocessing
import time
import random
from random import randint
from selenium import webdriver
from selenium.webdriver.support.ui import Select
manager = multiprocessing.Manager()
full_name = manager.list()
email = manager.list()
password = manager.list()
username = manager.list()
bio = manager.list()
verification_code = manager.list()
errors = manager.list()
success = manager.list()
# noinspection PyBroadException
class Sign_Up_Bot:
def __init__(self):
self.bot = webdriver.Firefox()
def get_mail(self, email_list, verification_list): # temporary email address
bot = self.bot
bot.get('https://tempail.com/') # reaching the website
# getting the value of the input, that contains the email and storing it to our global list
email_list.append(bot.find_element_by_xpath('//*[@id="eposta_adres"]').get_attribute('value'))
print(email_list[len(email_list) - 1]) # printing the email value
# clicking reload on the mails, and waiting for the instagram verification mail to appear
flag = True
while flag:
time.sleep(3)
# clicking refresh
bot.find_element_by_class_name('yenile-link').click()
try:
# trying to save the verification code instagram sent, to the verification global list
ver = bot.find_element_by_xpath('/html/body/section[2]/div/div/div/ul/li[2]/a/div[3]').text
verification_list.append(ver.split(' ')[0]) # getting just the verification code and not all the text
flag = False
except:
pass
# just printing the value of the verification code
print(verification_list[len(verification_list) - 1])
# doing nothing until we get an error
while len(errors) == 0 and len(success) == 0:
continue
# clicking reload on the mails, and waiting for the instagram verification mail to appear
flag = True
while flag:
time.sleep(3)
# clicking refresh
bot.find_element_by_class_name('yenile-link').click()
try:
# trying to find two emails, the first and the one that came now
mails = bot.find_elements_by_class_name('mail')
if len(mails) == 2:
ver = mails[0].find_element_by_class_name('baslik').text
verification_list.append(ver.split(' ')[0]) # getting just the numbers
flag = False
except:
pass
# just printing the value of the verification code
print(verification_list[len(verification_list) - 1])
def get_full_name(self, full_name_list): # random generated name
bot = self.bot
bot.get('https://www.name-generator.org.uk/quick/') # reaching the website
# getting a random name from a random generated name table
full_name_list.append(bot.find_elements_by_class_name('name_heading')[randint(0, 9)].text)
print(full_name_list[len(full_name_list) - 1]) # printing the name value
bot.close()
def get_full_greek_name(self, full_name_list): # random generated name
bot = self.bot
bot.get('https://www.fantasynamegenerators.com/greek_names.php') # reaching the website
# deciding between male and female names
flag = True
# keep trying while it clicks one of the two buttons, either for a male or a female name
while flag:
try:
# trying to click the button
bot.find_element_by_xpath(
'/html/body/div[2]/div[2]/div/div[4]/div[1]/input[' + str(randint(1, 2)) + ']').click()
# taking all the names, and giving them to the names variable
names = bot.find_element_by_id('result').text
# storing one random name to our global name list
full_name_list.append(names.split('\n')[randint(0, 9)])
flag = False
except:
pass
# printing the name stored
print(full_name_list[len(full_name_list) - 1])
bot.close()
def get_username(self, username_list): # generating a username with the given full name
bot = self.bot
bot.get('https://www.name-generator.org.uk/username/') # reaching the website
# waiting to get the full name first
flag = True
while flag:
if len(full_name) > 0:
print(full_name[0].split(' ')[0])
print(full_name[0].split(' ')[1])
try:
# clicking the cookie thing
bot.find_element_by_xpath('/html/body/div[1]/div/div/div/div[2]/div/button[2]').click()
except:
pass
try:
# closing an advertisement
bot.find_element_by_class_name('dmCatClose').click()
except:
pass
flag = False
# getting all the buttons with the class button
buttons = bot.find_elements_by_class_name('button')
for button in buttons:
# clicking only the buttons with the text Suggest
if button.get_attribute('value') == 'Suggest':
button.click()
bot.execute_script('window.scrollBy(0, 60);')
# from all the suggestions, blanking the first, last name, and middle name
bot.find_elements_by_class_name('sizeMedium')[0].clear()
bot.find_elements_by_class_name('sizeMedium')[1].clear()
bot.find_elements_by_class_name('sizeMedium')[2].clear()
# adding the name from the full_name list
bot.find_elements_by_class_name('sizeMedium')[0].send_keys(full_name[0].split(' ')[0])
bot.find_elements_by_class_name('sizeMedium')[2].send_keys(full_name[0].split(' ')[1])
# clicking the create submit form button
bot.find_element_by_class_name('create_form_submit').click()
# storing one random username to our global username list
username_list.append(bot.find_elements_by_class_name('username_item')[randint(0, 5)].text)
# printing the stored username
print(username_list[len(username_list) - 1])
bot.close()
def get_password(self, password_list): # generating a random password
bot = self.bot
bot.get('https://www.avast.com/random-password-generator') # reaching the website
bot.find_elements_by_class_name('checkmark')[3].click() # clicking the symbols
for i in range(randint(0, 5)):
if bool(random.getrandbits(1)): # random true false generator
# increasing the password length when it's true
bot.find_element_by_xpath(
'/html/body/div[3]/div[2]/div/section[1]/div/div[2]/div[2]/div[1]/div[1]').click()
else:
# decreasing the password length when it's false
bot.find_element_by_xpath(
'/html/body/div[3]/div[2]/div/section[1]/div/div[2]/div[2]/div[1]/div[2]').click()
# storing one random password to our global password list
password_list.append(bot.find_elements_by_class_name('password')[0].text)
# printing the stored password
print(password_list[len(password_list) - 1])
bot.close()
def instagram(self, errors_list, success_list):
bot = self.bot
bot.get('https://www.instagram.com/accounts/emailsignup/') # reaching instagram
flag = True
while flag: # moving forward only when we have pwd, name, username, and email saved on the globals
if len(full_name) > 0 and len(email) > 0 and len(username) > 0 and len(password) > 0:
flag = False
flag = True
while flag:
try:
bot.find_element_by_name('emailOrPhone').send_keys(email[len(email) - 1]) # input email
bot.find_element_by_name('fullName').send_keys(full_name[len(full_name) - 1]) # input name
bot.find_element_by_name('username').send_keys(username[len(username) - 1]) # input username
bot.find_element_by_name('password').send_keys(password[len(password) - 1]) # input password
time.sleep(2)
flag = False
except:
pass
time.sleep(2) # time sleep added so we can avoid the captcha
# clicking the next button on the credential form
buttons = bot.find_elements_by_tag_name('button')
for button in buttons:
if button.text == 'Sign up' or button.text == 'Next':
button.click()
time.sleep(1)
# checking if we get an error for the username of the account
try:
# checking if this paragraph exists anywhere, if it does, the name should be changed
print(bot.find_element_by_xpath('//*[@id="ssfErrorAlert"]').text)
spans = bot.find_elements_by_tag_name('span')
for span in spans:
if span.text == 'Refresh suggestion': # using instagram username generator if username exists
span.click()
for button in buttons: # clicking the next button once again
if button.text == 'Sign up' or button.text == 'Next':
button.click()
except:
pass
time.sleep(2) # time sleep added so we can avoid the captcha
# selecting random age
# selecting a year between 1975 and 2001 (18+ years old)
year = Select(bot.find_element_by_xpath(
'/html/body/div[1]/section/main/div/article/div/div[1]/div/div[4]/div/div/span/span[3]/select'))
year.select_by_value(str(randint(1975, 2001)))
# selecting a random month between january and december
month = Select(bot.find_element_by_xpath(
'/html/body/div[1]/section/main/div/article/div/div[1]/div/div[4]/div/div/span/span[1]/select'))
month.select_by_value(str(randint(1, 12)))
# month, but i have to consider what month has 28 or 30 days and what month has 31 days
flag = True
day = Select(bot.find_element_by_xpath(
'/html/body/div[1]/section/main/div/article/div/div[1]/div/div[4]/div/div/span/span[2]/select'))
while flag:
try:
day.select_by_value(str(randint(1, 31)))
flag = False
except:
pass
# finding all buttons
buttons = bot.find_elements_by_tag_name('button')
# clicking the next button again
for button in buttons:
if button.text == 'Sign up' or button.text == 'Next':
button.click()
# waiting to get the verification code from our email process and then we proceed
while len(verification_code) == 0:
continue
time.sleep(3) # captcha stuff
# finding the input for the verification code
inputs = bot.find_elements_by_tag_name('input')
for inp in inputs:
if inp.get_attribute('name') == 'email_confirmation_code':
inp.send_keys(verification_code[len(verification_code) - 1]) # entering the confirmation code
time.sleep(2) # time sleep added so we can avoid the captcha
# finding all buttons again
buttons = bot.find_elements_by_tag_name('button')
# pressing the next button again
for button in buttons:
if button.text == 'Sign up' or button.text == 'Next':
button.click()
time.sleep(3)
# instagram some times refuses to accept the first verification code, and we have to request a second one
try:
# trying to print the error message
print(bot.find_element_by_xpath(
'/html/body/div[1]/section/main/div/article/div/div[1]/div[2]/form/div/div[4]').text)
errors_list.append(True)
for button in buttons:
if button.text == 'Resend Code.':
# clicking the resend code button
button.click()
except:
pass
# waiting for the second verification code
while len(verification_code) == 1:
continue
if __name__ == '__main__':
bot1 = Sign_Up_Bot()
bot2 = Sign_Up_Bot()
bot3 = Sign_Up_Bot()
bot4 = Sign_Up_Bot()
bot5 = Sign_Up_Bot()
process1 = multiprocessing.Process(target=bot1.get_mail, args=(email, verification_code))
process2 = multiprocessing.Process(target=bot2.get_full_name, args=(full_name,))
process3 = multiprocessing.Process(target=bot3.get_username, args=(username,))
process4 = multiprocessing.Process(target=bot4.get_password, args=(password,))
process5 = multiprocessing.Process(target=bot5.instagram, args=(errors, success,))
process1.start()
process2.start()
process3.start()
process4.start()
process5.start()
process1.join()
process2.join()
process3.join()
process4.join()
process5.join()
# Websites used for this autogenerated Instagram bot
# https://tempail.com/ temporary email address
# https://www.fantasynamegenerators.com/greek_names.php greek name generator
# https://www.name-generator.org.uk/quick/ world wide name generator
# https://www.name-generator.org.uk/username/ username generator
# ---------------------------------------------------------------