-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
109 lines (88 loc) · 3.58 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
# autor: marcy
## boot insta sorteio
import time
import random
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from itertools import combinations
import pandas as pd
class InstaBot:
def __init__(self, username, passaword, amigosComentarios, repete):
self.username = username
self.passaword = passaword
self.amigosComentarios = int(amigosComentarios)
self.repete = int(repete)
#path do webdrive - interface com o navegador escolhido (geck)
self.driver = webdriver.Firefox(executable_path=r"C:\Users\marcy\Desktop\geckodriver-v0.26.0-win64\geckodriver.exe")
def login(self):
cont = []
driver = self.driver
driver.get('https://www.instagram.com')
time.sleep(5)
campo_user = driver.find_element_by_xpath(r"//input[@name='username']")
campo_user.click()
campo_user.clear()
campo_user.send_keys(self.username)
campo_pass = driver.find_element_by_xpath(r"//input[@name='password']")
campo_pass.click()
campo_pass.clear()
campo_pass.send_keys(self.passaword)
campo_pass.send_keys(Keys.RETURN)
time.sleep(9)
i = 0
jj = 0
foller = ['@fulano1', '@fulano2', '@ciclano1'] # add o seguidores
perList = [' '.join(str(i) for i in x) for x in combinations(foller, self.amigosComentarios)] # [' @sdjdisjv @ljgijfdiogj',...]
random.shuffle(perList)
while jj < len(perList):
if cont.count(perList[jj].split()[0]) < self.repete and cont.count(perList[jj].split()[1]) < self.repete:
self.comentando(perList[jj])
cont = perList[jj].split() + cont
print(str(len(cont)/2)+ " " + str(cont))
i = i + 1
jj = jj + 1
if i == 60:
i = 0
print('time')
# o instagram tem numero limite de comentarios por hora, colocar um time para regular isso.
time.sleep(60*30) # espera 30 min
@staticmethod
def digitando(text,onde):
for letra in text:
onde.send_keys(letra)
time.sleep(random.randint(1,5)/15)
def comentando(self,comen):
driver = self.driver
driver.get("https://www.instagram.com/p/...") # a url da pagina do sorteio
time.sleep(3)
try:
driver.find_element_by_class_name('Ypffh').click()
campo_com = driver.find_element_by_class_name('Ypffh')
time.sleep(random.randint(2,6))
self.digitando(comen, campo_com)
'''pes = []
aux = 0
random.shuffle(foller)
while len(pes) != 2:
r = random.choice(foller)
if (r not in pes) and (list.count(r) < 5) and ([aux,r] not in cont) and ([r,aux] not in cont) :
pes.append(r)
aux = r
list.append(r)
self.digitando(pes, campo_com)
cont.append(pes)
print(list)
print(len(list)/2)
'''
time.sleep(3)
driver.find_element_by_xpath(r"//button[contains(text(),'Post')]").click()
time.sleep(random.randint(5, 10))
except Exception as e:
print(e)
time.sleep(10)
log = input(r'login: ')
senha= input(r'Senha: ')
amigosComentarios = input(r'Numero de amigos por comentario: ')
repete = input(r'Quantos vezes e possivel repetir cada amigo: ')
bot = InstaBot(log, senha, amigosComentarios = amigosComentarios, repete = repete) # username,senha
bot.login()