-
Notifications
You must be signed in to change notification settings - Fork 0
/
igBot.py
65 lines (54 loc) · 2.03 KB
/
igBot.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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import random
class InstagramBot:
def __init__(self, username, password):
self.username = username
self.password = password
self.driver = webdriver.Firefox(
executable_path="./utils/geckodriver")
def login(self):
driver = self.driver
driver.get("https://instagram.com.br")
time.sleep(3)
username = driver.find_element_by_xpath(
"//input[@name='username']")
username.click()
username.clear()
username.send_keys(self.username)
password = driver.find_element_by_xpath(
"//input[@name='password']")
password.click()
password.clear()
password.send_keys(self.password)
password.send_keys(Keys.RETURN)
def comment(self):
driver = self.driver
driver.get(
"[post-url]")
time.sleep(3)
try:
time.sleep(2)
comentarios = ["❤️", "🚀", "👋🏽", "🙅🏽♂️", "😁", "👍🏽", "😇",
"🤓", "🦊", "🌻", "😊", "😻", "🤠", "🙌🏽", "😽", "🙀", "💪🏽"]
for i in range(100):
comment_input_area = driver.find_element_by_class_name(
'Ypffh')
comment_input_area.click()
time.sleep(random.randint(4, 6))
comment_input_area = driver.find_element_by_class_name(
'Ypffh.focus-visible')
comment_input_area.click()
comment_input_area.send_keys(random.choice(comentarios))
time.sleep(random.randint(4, 6))
driver.find_element_by_xpath(
"//button[contains(text(), 'Post')]").click()
time.sleep(random.randint(3, 6))
driver.refresh()
except Exception as e:
print(e)
Bot = InstagramBot('[username]', '[password]')
Bot.login()
time.sleep(3)
Bot.comment()