Advertisement
Guest User

Untitled

a guest
Dec 1st, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. from selenium import webdriver
  2. from time import sleep
  3. from selenium.webdriver.common.action_chains import ActionChains
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.support.ui import WebDriverWait
  6. from selenium.webdriver.support import expected_conditions as EC
  7. from selenium.webdriver.common.keys import Keys
  8. from selenium.webdriver.support.ui import Select
  9. import time
  10. import random
  11.  
  12. username = 'oneillautos'
  13. password = 'Businessboys'
  14. keyword = 'rdbla'
  15.  
  16. #Start a new browsing session
  17. browser = webdriver.Chrome()
  18. #navigating to webpage
  19. browser.get('https://www.instagram.com/')
  20. #find login link
  21. log_elem = browser.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div[2]/p/a')
  22. #click it
  23. log_elem.click()
  24. # find form inputs and enter data
  25. inputs = browser.find_elements_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div[1]/div/form/div[1]/div/input')
  26. input2 = browser.find_elements_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div[1]/div/form/div[2]/div/input')
  27.  
  28. ActionChains(browser)\
  29. .move_to_element(inputs[0]).click()\
  30. .send_keys(username) \
  31. .move_to_element(input2[0]).click()\
  32. .send_keys(password) \
  33. .perform()
  34.  
  35.  
  36. #find log in button and click it
  37. loginbttn = browser.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div[1]/div/form/span/button')
  38.  
  39. ActionChains(browser)\
  40. .move_to_element(loginbttn)\
  41. .click().perform()
  42.  
  43. #find search bar and type in data
  44. searchbox = WebDriverWait(browser, 10).until(
  45. EC.visibility_of_element_located(
  46. (By.XPATH, "//input[@placeholder='Search']")
  47. )
  48. )
  49.  
  50. #ARROW_DOWN = u'\ue015'
  51.  
  52.  
  53. ActionChains(browser)\
  54. .move_to_element(searchbox).click()\
  55. .send_keys(keyword) \
  56. .perform()
  57.  
  58. #element of first dropdown menu item
  59. clickelm = WebDriverWait(browser, 10).until(
  60. EC.visibility_of_element_located(
  61. (By.XPATH, "//a[@class='_gimca']")
  62. )
  63. )
  64.  
  65. ActionChains(browser)\
  66. .move_to_element(clickelm).click()\
  67. .perform()
  68.  
  69. sleep(2)
  70.  
  71. folopath = '//a[@href="/' + keyword + '/followers/"]'
  72. #find the followers
  73. followers = browser.find_element_by_xpath(folopath)
  74.  
  75. ActionChains(browser)\
  76. .move_to_element(followers).click()\
  77. .perform()
  78. #scrolling feature
  79. i = 0
  80. while 1 == 1:
  81.  
  82. fb = '//div[@class="_gs38e"]'
  83. fbox = WebDriverWait(browser, 10).until(
  84. EC.visibility_of_element_located(
  85. (By.XPATH, fb)
  86. )
  87. )
  88. browser.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", fbox)
  89. time.sleep(random.randint(500,1000)/1000)
  90. sleep(2)
  91. while 1 == 1:
  92. popup = WebDriverWait(browser, 25).until(
  93. EC.element_to_be_clickable(
  94. (By.XPATH, '//span/button[text()="Follow"]')
  95. )
  96. )
  97. ActionChains(browser)\
  98. .move_to_element(popup).click()\
  99. .perform()
  100. i += 1
  101. print(i)
  102. sleep(31)
  103.  
  104.  
  105.  
  106. #make sure browser stays open
  107. sleep(5)
  108. #exit
  109. browser.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement