Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from time import sleep
- from selenium.webdriver.common.action_chains import ActionChains
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.support.ui import Select
- import time
- import random
- username = 'oneillautos'
- password = 'Businessboys'
- keyword = 'rdbla'
- #Start a new browsing session
- browser = webdriver.Chrome()
- #navigating to webpage
- browser.get('https://www.instagram.com/')
- #find login link
- log_elem = browser.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div[2]/p/a')
- #click it
- log_elem.click()
- # find form inputs and enter data
- inputs = browser.find_elements_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div[1]/div/form/div[1]/div/input')
- input2 = browser.find_elements_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div[1]/div/form/div[2]/div/input')
- ActionChains(browser)\
- .move_to_element(inputs[0]).click()\
- .send_keys(username) \
- .move_to_element(input2[0]).click()\
- .send_keys(password) \
- .perform()
- #find log in button and click it
- loginbttn = browser.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div[1]/div/form/span/button')
- ActionChains(browser)\
- .move_to_element(loginbttn)\
- .click().perform()
- #find search bar and type in data
- searchbox = WebDriverWait(browser, 10).until(
- EC.visibility_of_element_located(
- (By.XPATH, "//input[@placeholder='Search']")
- )
- )
- #ARROW_DOWN = u'\ue015'
- ActionChains(browser)\
- .move_to_element(searchbox).click()\
- .send_keys(keyword) \
- .perform()
- #element of first dropdown menu item
- clickelm = WebDriverWait(browser, 10).until(
- EC.visibility_of_element_located(
- (By.XPATH, "//a[@class='_gimca']")
- )
- )
- ActionChains(browser)\
- .move_to_element(clickelm).click()\
- .perform()
- sleep(2)
- folopath = '//a[@href="/' + keyword + '/followers/"]'
- #find the followers
- followers = browser.find_element_by_xpath(folopath)
- ActionChains(browser)\
- .move_to_element(followers).click()\
- .perform()
- #scrolling feature
- i = 0
- while 1 == 1:
- fb = '//div[@class="_gs38e"]'
- fbox = WebDriverWait(browser, 10).until(
- EC.visibility_of_element_located(
- (By.XPATH, fb)
- )
- )
- browser.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", fbox)
- time.sleep(random.randint(500,1000)/1000)
- sleep(2)
- while 1 == 1:
- popup = WebDriverWait(browser, 25).until(
- EC.element_to_be_clickable(
- (By.XPATH, '//span/button[text()="Follow"]')
- )
- )
- ActionChains(browser)\
- .move_to_element(popup).click()\
- .perform()
- i += 1
- print(i)
- sleep(31)
- #make sure browser stays open
- sleep(5)
- #exit
- browser.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement