Skip to content

Instantly share code, notes, and snippets.

@mottet-dev
Last active Sep 11, 2018
Embed
What would you like to do?
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