-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
115 lines (88 loc) · 3.35 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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import random
import sys
import time
class GrowthBot:
username = '<INSERT USERNAME/EMAIL>'
password = '<INSERT PASSWORD>'
# enter all the hashtags you'd like the bot to search through and comment on, separated by a comma
hashtags = ['chickens']
# remove or add comments you want the bot to leave to this list
comments = [
'Your posts are amazing', 'Amazing work. Keep going!', 'Your photos are magnificent',
'Your work fascinates me!', 'I like how you put your posts together', 'Great job',
'What a really nice photo, great job!', 'Well done!', 'Your posts are amazing',
]
links = []
price = 0.0
def __init__(self):
self.browser = webdriver.Firefox()
self.login()
self.hustle()
def login(self):
self.browser.get(
'https://www.instagram.com/accounts/login/?source=auth_switcher')
time.sleep(2)
username_field = self.browser.find_element_by_xpath(
"//input[@name='username']")
username_field.clear()
username_field.send_keys(self.username)
time.sleep(1)
password_field = self.browser.find_element_by_xpath(
"//input[@name='password']")
password_field.clear()
password_field.send_keys(self.password)
time.sleep(1)
login_button = self.browser.find_element_by_xpath(
"//button[@type='submit']")
login_button.click()
time.sleep(2)
def hustle(self):
self.getTopPosts()
self.execute()
self.finalize()
def getTopPosts(self):
for hashtag in self.hashtags:
self.browser.get(
'https://www.instagram.com/explore/tags/' + hashtag + '/')
time.sleep(2)
links = self.browser.find_elements_by_tag_name('a')
def condition(link): return '.com/p/' in link.get_attribute('href')
valid_links = list(filter(condition, links))
for i in range(0, 9):
link = valid_links[i].get_attribute('href')
if link not in self.links:
self.links.append(link)
def execute(self):
for link in self.links:
self.browser.get(link)
time.sleep(1)
self.browser.execute_script(
"window.scrollTo(0, document.body.scrollHeight);")
time.sleep(1)
self.comment()
time.sleep(2)
self.like()
self.price += 0.02
sleeptime = random.randint(18, 28)
time.sleep(sleeptime)
def comment(self):
def comment_input(): return self.browser.find_element_by_tag_name('textarea')
comment_input().click()
comment_input().clear()
comment = random.choice(self.comments)
for letter in comment:
comment_input().send_keys(letter)
delay = random.randint(1, 7) / 30
time.sleep(delay)
comment_input().send_keys(Keys.RETURN)
def like(self):
def like_button(): return self.browser.find_element_by_xpath(
'//span[@class="glyphsSpriteHeart__outline__24__grey_9 u-__7"]')
like_button().click()
def finalize(self):
print('All finished!')
self.browser.close()
sys.exit()
growth_bot = GrowthBot()