-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
45 lines (36 loc) · 1.19 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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import random
import os
from os import environ
from decouple import config
class InstagramBot:
def __init__(self,username,password):
self.username = username
self.password = password
self.bot = webdriver.Firefox(executable_path = '/Users/Musavveer Rehaman/Downloads/geckodriver.exe')
def login(self):
bot = self.bot
bot.get('https://www.instagram.com/accounts/login/')
time.sleep(3)
email = bot.find_element_by_name('username').send_keys(self.username)
password = bot.find_element_by_name('password').send_keys(self.password + Keys.RETURN)
time.sleep(3)
def searchHashtag(self,hashtag):
bot = self.bot
bot.get('https://www.instagram.com/explore/tags/' + hashtag)
def likePhotos(self,amount):
bot = self.bot
bot.find_element_by_class_name('v1Nh3').click()
i = 1
while i <= amount:
time.sleep(1)
bot.find_element_by_class_name('fr66n').click()
bot.find_element_by_class_name('coreSpriteRightPaginationArrow').click()
time.sleep(1)
i += 1
insta = InstagramBot(config['Your_Username'], config['Your_Password'])
insta.login()
insta.searchHashtag('Hashtags')
insta.likePhotos(2)