├── .gitignore ├── README.md ├── accounts.json ├── comments.txt ├── requirements.txt ├── run.py └── tags.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /env 2 | .vscode/ 3 | .env 4 | /.vscode 5 | .vscode/* 6 | .vscode/* 7 | !.vscode/settings.json 8 | !.vscode/tasks.json 9 | !.vscode/launch.json 10 | !.vscode/extensions.json 11 | *.code-workspace 12 | 13 | # Local History for Visual Studio Code 14 | .history/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Instagram comment bot with account rotation feature. 2 | This is an instagram bot builded with python and selenium library during the Automate Social Median with Python series in **TopNotch Programmer** youtube channel. 3 | Please make sure to subscribe to my channel: https://youtube.com/c/TopNotchProgrammer. 4 | 5 | ## Setup Bot 6 | 1. Close this github repo in your computer. 7 | 2. Install requirements using ```pip install -r requirements.txt```. 8 | 3. Open accounts.json and paste your accounts as the example. 9 | 4. Open tags.txt and put your tags list and comments.txt to put your comments list. 10 | 5. Run the bot using this command ```python run.py``` 11 | 12 | This bot is built in the youtube series of *TopNotch Programmer* so if you want to learn more about just go to the channel and follow videos. 13 | 14 | ## Donate Here: PayPal --> https://paypal.me/redidev. 15 | 16 | Thank You! 17 | -------------------------------------------------------------------------------- /accounts.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "username": "your-username", 4 | "password": "your-password" 5 | }, 6 | 7 | { 8 | "username": "another-username", 9 | "password": "password" 10 | } 11 | ] -------------------------------------------------------------------------------- /comments.txt: -------------------------------------------------------------------------------- 1 | Nice 2 | I like it 3 | Hello 4 | Loved it -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | certifi==2021.5.30 2 | chardet==4.0.0 3 | colorama==0.4.4 4 | configparser==5.0.2 5 | crayons==0.4.0 6 | idna==2.10 7 | requests==2.25.1 8 | selenium==3.141.0 9 | urllib3==1.26.5 10 | webdriver-manager==3.4.2 11 | -------------------------------------------------------------------------------- /run.py: -------------------------------------------------------------------------------- 1 | import time 2 | import json 3 | import random 4 | from selenium import webdriver 5 | from webdriver_manager.chrome import ChromeDriverManager as CM 6 | from selenium.webdriver.common.action_chains import ActionChains 7 | from selenium.webdriver.common.keys import Keys 8 | from selenium.common.exceptions import NoSuchElementException 9 | from webdriver_manager.utils import download_file 10 | from selenium.webdriver.support.ui import WebDriverWait 11 | from selenium.webdriver.support import expected_conditions as EC 12 | from selenium.webdriver.common.by import By 13 | 14 | 15 | f = open('accounts.json',) 16 | datas = json.load(f) 17 | 18 | with open('tags.txt', 'r') as f: 19 | tags = [line.strip() for line in f] 20 | 21 | 22 | def doesnt_exist(driver, xpath): 23 | try: 24 | driver.find_element_by_xpath(xpath) 25 | except NoSuchElementException: 26 | return True 27 | else: 28 | return False 29 | 30 | 31 | def random_comment(): 32 | with open('comments.txt', 'r') as f: 33 | comments = [line.strip() for line in f] 34 | comment = random.choice(comments) 35 | return comment 36 | 37 | 38 | def main(data): 39 | options = webdriver.ChromeOptions() 40 | 41 | mobile_emulation = { 42 | "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/90.0.1025.166 Mobile Safari/535.19"} 43 | 44 | options.add_experimental_option("mobileEmulation", mobile_emulation) 45 | options.add_argument("--log-level=3") 46 | 47 | bot = webdriver.Chrome(options=options, executable_path=CM().install()) 48 | bot.set_window_size(500, 950) 49 | 50 | bot.get('https://instagram.com') 51 | 52 | # Login section========================== 53 | time.sleep(3) 54 | print('Logging in...') 55 | bot.find_element_by_xpath( 56 | '//*[@id="react-root"]/section/main/article/div/div/div/div[3]/button[1]').click() 57 | time.sleep(2) 58 | 59 | username_field = bot.find_element_by_xpath( 60 | '//*[@id="loginForm"]/div[1]/div[3]/div/label/input') 61 | username_field.send_keys(data["username"]) 62 | 63 | time.sleep(1) 64 | 65 | password_field = bot.find_element_by_xpath( 66 | '//*[@id="loginForm"]/div[1]/div[4]/div/label/input') 67 | password_field.send_keys(data["password"]) 68 | 69 | time.sleep(1) 70 | 71 | bot.find_element_by_xpath( 72 | '//*[@id="loginForm"]/div[1]/div[6]/button').click() 73 | 74 | time.sleep(6) 75 | # ========================================== 76 | 77 | # Fetching posts============================ 78 | 79 | tag = random.choice(tags) 80 | print('Fetching posts for this tag----> ' + tag) 81 | link = "https://www.instagram.com/explore/tags/" + tag 82 | 83 | bot.get(link) 84 | time.sleep(4) 85 | 86 | for i in range(1): 87 | ActionChains(bot).send_keys(Keys.END).perform() 88 | time.sleep(2) 89 | 90 | row1 = bot.find_element_by_xpath( 91 | '//*[@id="react-root"]/section/main/article/div[2]/div/div[1]') 92 | row2 = bot.find_element_by_xpath( 93 | '//*[@id="react-root"]/section/main/article/div[2]/div/div[2]') 94 | 95 | r_link1 = row1.find_elements_by_tag_name('a') 96 | r_link2 = row2.find_elements_by_tag_name('a') 97 | links = r_link1 + r_link2 98 | 99 | urls = [] 100 | 101 | for i in links: 102 | if i.get_attribute('href') != None: 103 | urls.append(i.get_attribute('href')) 104 | 105 | # ======================================================== 106 | 107 | # Comment ===================================== 108 | 109 | for url in urls: 110 | print('Commenting to this post---> ' + url) 111 | comment = random_comment() 112 | bot.get(url) 113 | bot.implicitly_wait(1) 114 | bot.execute_script("window.scrollTo(0, window.scrollY + 300)") 115 | 116 | time.sleep(random.randint(5, 10)) 117 | 118 | # Like feature 119 | # bot.find_element_by_xpath( 120 | # '/html/body/div[1]/section/main/div/div/article/div[3]/section[1]/span[1]/button').click() 121 | # time.sleep(2) 122 | 123 | bot.find_element_by_xpath( 124 | '//*[@id="react-root"]/section/main/div/div/article/div/div[3]/div/div/section[1]/span[2]/button').click() 125 | 126 | if doesnt_exist(bot, '//*[@id="react-root"]/section/main/section/div'): 127 | print('Skiped - comments disabled') 128 | else: 129 | find_textarea = ( 130 | By.XPATH, '//*[@id="react-root"]/section/main/section/div/form/textarea') 131 | WebDriverWait(bot, 50).until( 132 | EC.presence_of_element_located(find_textarea) 133 | ) 134 | comment_box = bot.find_element(*find_textarea) 135 | WebDriverWait(bot, 50).until( 136 | EC.element_to_be_clickable(find_textarea) 137 | ) 138 | comment_box.click() 139 | comment_box.send_keys(comment) 140 | 141 | time.sleep(2) 142 | 143 | find_button = ( 144 | By.XPATH, '//*[@id="react-root"]/section/main/section/div/form/button') 145 | WebDriverWait(bot, 50).until( 146 | EC.presence_of_element_located(find_button) 147 | ) 148 | button = bot.find_element(*find_button) 149 | WebDriverWait(bot, 50).until( 150 | EC.element_to_be_clickable(find_button) 151 | ) 152 | button.click() 153 | 154 | time.sleep(random.randint(7, 30)) 155 | 156 | bot.close() 157 | 158 | 159 | while True: 160 | for data in datas: 161 | main(data) 162 | -------------------------------------------------------------------------------- /tags.txt: -------------------------------------------------------------------------------- 1 | rap 2 | love 3 | python 4 | javascript --------------------------------------------------------------------------------