Created
May 26, 2020 14:26
-
-
Save meet100ni/52cc6b14320ac3b4f123ac8bc77d1fdc to your computer and use it in GitHub Desktop.
Instagram BOT for like and comment any user's photo by set limits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
import time | |
import random | |
class InstaLikeBOT: | |
def __init__(self, username, password): | |
self.username = username | |
self.password = password | |
self.driver = webdriver.Firefox(executable_path="D:\geckodriver-v0.26.0-win64\geckodriver.exe") # Open Firefox | |
def login(self): | |
driver = self.driver | |
driver.get("https://www.instagram.com") # Open Instagram website | |
time.sleep(3) | |
username = driver.find_element_by_name("username") # Find Username Input Field | |
username.send_keys(self.username) # Enter Username | |
password = driver.find_element_by_name("password") # Find Password Input Field | |
password.send_keys(self.password + Keys.RETURN) # Enter Password and Press Login Key | |
time.sleep(3) | |
def searchClient(self, client_username): | |
driver = self.driver | |
driver.get("https://www.instagram.com/" + client_username + "/") # Open UserPage | |
def like_and_comment_Photo(self, amount): | |
driver = self.driver | |
totalPost = driver.find_element_by_class_name("g47SY ").text # Found total number of posts | |
print("Total Posts: ", totalPost) # Print total number of posts | |
driver.find_element_by_class_name('v1Nh3').click() # Click on next button | |
i = 1 | |
while i <= amount or amount >= 1: | |
random_time = random.randint(5, 7) # generate random time between 5 to 7 second | |
time.sleep(random_time) | |
driver.find_element_by_class_name("fr66n").click() | |
comments = ['amazing', 'awesome', 'wow..!!', 'Perfect', 'Superb..!!', 'Jordar', 'Bapu Bapu', 'Ha Moj Ha'] | |
x = random.choice(comments) # generate random comment | |
click_comment_button = driver.find_element_by_class_name("_15y0l") # find comment button | |
click_comment_button.click() # Click on comment button | |
click_comment_area = driver.find_element_by_class_name("Ypffh") # Find Textarea | |
click_comment_area.send_keys(x) # Set comment on TextArea | |
time.sleep(3) | |
click_comment_button = driver.find_element_by_xpath( | |
"/html/body/div[4]/div[2]/div/article/div[2]/section[3]/div/form/button") # Find send button | |
click_comment_button.click() # Click on send button | |
print("Photoes left: ", amount-1) # Reverse pic count with -1 number | |
amount -= 1 # Reverse login in while loop | |
time.sleep(2) | |
driver.find_element_by_class_name("coreSpriteRightPaginationArrow").click() # Click on nect >> button | |
i += 1 # Click untill amount | |
driver.get("https://www.instagram.com/" + self.username) # After completing process come to User Homepage | |
insta = InstaLikeBOT('<your username>', '<your password>') | |
insta.login() | |
insta.searchClient('meet__soni') | |
# Give like to giver number of photos | |
insta.like_and_comment_Photo(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment