forked from ekarizki31/BotCommentInsta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
77 lines (66 loc) · 2.66 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
from selenium import webdriver
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support import ui
import time
from random import randint
class instagramBot:
def __init__(self, username, password, link):
self.username = username
self.password = password
self.link = link
self.driver = webdriver.Firefox(executable_path=r'geckodriver.exe')
def login(self):
driver = self.driver
driver.get('https://www.instagram.com')
time.sleep(10)
user_element = driver.find_element_by_xpath("//input[@name='username']")
user_element.clear()
user_element.send_keys(self.username)
password_element = driver.find_element_by_xpath("//input[@name='password']")
password_element.clear()
password_element.send_keys(self.password)
password_element.send_keys(Keys.RETURN)
time.sleep(10)
x=1
while x:
self.comment_url(self.link)
x+=1
print(x)
def comment_url(self, link):
arq = open("lista_perfis.txt", "r")
list = []
linhas = arq.readlines()
cont = 0
for linha in linhas:
list.append(linha)
cont = cont +1
arq.close()
driver = self.driver
driver.get(link)
commentSection = ui.WebDriverWait(self.driver, 100).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "textarea.Ypffh")))
self.driver.execute_script("arguments[0].scrollIntoView(true);",
commentSection)
while (1 == 1):
try:
commentSection = ui.WebDriverWait(self.driver, 100).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "textarea.Ypffh")))
comment = list[randint(0,(cont-1))]
commentSection.send_keys(comment)
comment = list[randint(0, (cont-1))]
commentSection.send_keys(' ')
commentSection.send_keys(comment)
comment = list[randint(0, (cont-1))]
commentSection.send_keys(' ')
commentSection.send_keys(comment)
commentSection.send_keys(Keys.ENTER)
time.sleep(randint(100,150))
break
except Exception:
time.sleep(randint(100,150))
robo = instagramBot('InsertYourUsername', 'InsertYourPassword*','https://www.instagram.com/insertyourphotolink')
robo.login()
#this is my changes