Skip to content

Instantly share code, notes, and snippets.

@kmandana
kmandana / Instagrambot.py
Last active July 12, 2025 06:13
Instagram Bot
class InstagramBot():
def __init__(self, username, password, url, msg):
self.username = username
self.password = password
self.url = url
self.msg = msg
self.browser = webdriver.Chrome()
@kmandana
kmandana / Instagrambot.py
Last active April 18, 2020 18:23
signIn method
def signIn(self):
self.browser.get("https://www.instagram.com")
username_element = WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#react-root > section > main > article > div.rgFsT > div:nth-child(1) > div > form > div:nth-child(2) > div > label > input")))
username_element.click()
username_element.send_keys(self.username)
password_element = self.browser.find_element_by_css_selector("#react-root > section > main > article > div.rgFsT > div:nth-child(1) > div > form > div:nth-child(3) > div > label > input")
password_element.click()
password_element.send_keys(self.password)
password_element.send_keys(Keys.RETURN)
@kmandana
kmandana / Instabot.py
Last active April 18, 2020 17:57
Notification Preference popup
WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body > div.RnEpo.Yx5HN > div > div > div.mt3GC > button.aOOlW.HoLwm'))).click()
@kmandana
kmandana / Instagrambot.py
Created April 18, 2020 18:50
Click likes Button
def scrapeUsernames(self):
self.browser.get(self.url)
try:
likes = WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#react-root > section > main > div > div.ltEKP > article > div.eo2As > section.EDfFK.ygqzn > div > div.Nm9Fw > button')))
no_of_likes = likes.text.replace('others', '').replace('likes', '').replace(',', '').strip()
except:
likes = WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#react-root > section > main > div > div.ltEKP > article > div.eo2As > section.EDfFK.ygqzn > div > div > button')))
no_of_likes = likes.text.replace('others', '').replace('likes', '').replace(',', '').strip()
likes.click()
@kmandana
kmandana / Instagrambot.py
Last active April 18, 2020 19:28
Scraping Usernames
user_names = list()
while len(user_names) < int(no_of_likes):
popup = WebDriverWait(self.browser, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body > div.RnEpo.Yx5HN > div > div.Igw0E.IwRSH.eGOV_.vwCYk.i0EQd > div')))
raw_data = BS(popup.get_attribute('innerHTML'), 'html.parser')
for each in raw_data.find_all('a'):
if 'title' in each.attrs.keys():
if each.attrs['title'] not in user_names:
user_names.append(each.attrs['title'])
self.browser.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", popup)
time.sleep(1)
@kmandana
kmandana / Instagrambot.py
Created April 18, 2020 20:22
Sending Message
def send_likes(self, usernames):
for username in usernames:
url = 'https://www.instagram.com/' + username
self.browser.get(url)
button = self.browser.find_element_by_css_selector('button')
if button.text == "Message":
button.click()
text_box = WebDriverWait(self.browser, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#react-root > section > div > div.Igw0E.IwRSH.eGOV_._4EzTm > div > div > div.DPiy6.Igw0E.IwRSH.eGOV_.vwCYk > div.uueGX > div > div.Igw0E.IwRSH.eGOV_._4EzTm > div > div > div.Igw0E.IwRSH.eGOV_.vwCYk.ItkAi > textarea")))
text_box.send_keys(self.msg)
send_button = self.browser.find_element_by_css_selector('#react-root > section > div > div.Igw0E.IwRSH.eGOV_._4EzTm > div > div > div.DPiy6.Igw0E.IwRSH.eGOV_.vwCYk > div.uueGX > div > div.Igw0E.IwRSH.eGOV_._4EzTm > div > div > div.Igw0E.IwRSH.eGOV_._4EzTm.JI_ht > button')