This file contains hidden or 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
| 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') |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| 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() |
This file contains hidden or 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
| 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() |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| 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() |