Skip to content

Instantly share code, notes, and snippets.

@mottet-dev
Last active September 11, 2018 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mottet-dev/4d9f062d3060a49e6a71783a9d2bcc59 to your computer and use it in GitHub Desktop.
Save mottet-dev/4d9f062d3060a49e6a71783a9d2bcc59 to your computer and use it in GitHub Desktop.
InstagramBot - getUserFollowers
def getUserFollowers(self, username, max):
self.browser.get('https://www.instagram.com/' + username)
followersLink = self.browser.find_element_by_css_selector('ul li a')
followersLink.click()
time.sleep(2)
followersList = self.browser.find_element_by_css_selector('div[role=\'dialog\'] ul')
numberOfFollowersInList = len(followersList.find_elements_by_css_selector('li'))
followersList.click()
actionChain = webdriver.ActionChains(self.browser)
while (numberOfFollowersInList < max):
actionChain.key_down(Keys.SPACE).key_up(Keys.SPACE).perform()
numberOfFollowersInList = len(followersList.find_elements_by_css_selector('li'))
print(numberOfFollowersInList)
followers = []
for user in followersList.find_elements_by_css_selector('li'):
userLink = user.find_element_by_css_selector('a').get_attribute('href')
print(userLink)
followers.append(userLink)
if (len(followers) == max):
break
return followers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment