Open In App

How to scroll down followers popup in Instagram ?

Last Updated : 26 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Here, in this article, we are going to discuss How to scroll down followers popup on Instagram Using Python. With the selenium, we will automate our browsers and performs automation on Instagram’s Social Website. Before going to practical implementation, we need to install the Selenium Library using the pip command.

Installation:

pip install Selenium

Now, Let’s check whether our selenium is installed or not. If the below command did not give any error that means selenium is successfully installed.

Python3




import selenium
print(selenium.__version__)


Output:

3.141.0

Approach:

Now, Let’s discuss the approach to how we can perform scrolling down functionality. Using while loop, We will scroll down the followers pop-up window until our program reached till the last follower. First, we will automate the login process with our login id and password and then go to the GeeksforGeeks Instagram page. Click on the follower’s button and then perform the scrolling down operation on the popup window. 

  • First, we need to import the time module and all necessary classes or methods from the Selenium Library.
  • Installing Chrome Web Driver through which we will perform all tasks on Chrome Web Browser. Same as Chrome, we can install any other browsers such as Edge, IE, Firefox, and many more.
driver = webdriver.Chrome(ChromeDriverManager().install())

Using the above line, we do not require to have any physical driver present in our system. This line will automatically install the required chrome web driver using the web.

  • Open the Website using the driver object and get() method with the given URL.
driver.get("http://www.instagram.com")
  • WebDriverWait is also called Explicit Wait. Explicit Wait is code which defines to wait for a certain condition to occur before proceeding further. in this code, With the help of CSS_SELECTOR, we will find the username and password fields for login purpose.

username = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, “input[name=’username’]”)))

password = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, “input[name=’password’]”)))

  • Now, before putting the username and password in the selected field, first, clear the username and password fields using the clear() method. Then, Put the username and password value using send_keys() method.
username.clear()
username.send_keys("<Enter_Your_Username")
password.clear()
password.send_keys("<Enter_Your_Password>")
  • Click on the Login button using CSS_SELECTOR.

button = WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.CSS_SELECTOR, “button[type=’submit’]”))).click()

  • We are done with Instagram Login. Now, We can open our target profile URL on which we will perform the scrolling.
driver.get("https://www.instagram.com/geeks_for_geeks/followers/")

Here, in this practical implementation, we are using geeksforgeeks followers pop up for scrolling.

  • Click on followers button using find_element_by_partial_link_text method.
  • Find the pop-up window element from a webpage using XPATH. On the pop-up window, we will use a while loop for performing the scrolling until the program gets reached to the last followers. That’s why we take our loop as TRUE always.
  • Finally, Once we are done with our task. We will use the quit() method for closing the resources.

Below is the full implementation:

Python3




import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.microsoft import EdgeChromiumDriverManager
  
driver = webdriver.Chrome(ChromeDriverManager().install())
  
# open the webpage
  
# target username
username = WebDriverWait(
    driver, 10).until(EC.element_to_be_clickable(
        (By.CSS_SELECTOR, "input[name='username']")))
  
# target Password
password = WebDriverWait(
    driver, 10).until(EC.element_to_be_clickable(
        (By.CSS_SELECTOR, "input[name='password']")))
  
# enter username and password
username.clear()
username.send_keys("<Enter_Your_Username>")
password.clear()
password.send_keys("<Enter_Your_Password>")
  
# target the login button and click it
button = WebDriverWait(
    driver, 2).until(EC.element_to_be_clickable(
        (By.CSS_SELECTOR, "button[type='submit']"))).click()
  
time.sleep(5)
  
  
driver.find_element_by_partial_link_text("follower").click()
  
pop_up_window = WebDriverWait(
    driver, 2).until(EC.element_to_be_clickable(
        (By.XPATH, "//div[@class='isgrP']")))
  
# Scroll till Followers list is there
while True:
    driver.execute_script(
        'arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;'
      pop_up_window)
    time.sleep(1)
  
driver.quit()


Output:



Previous Article
Next Article

Similar Reads

Python - API.followers() in Tweepy
Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user.
3 min read
Python Tweepy – Getting the number of followers of a user
In this article we will see how we can get the number of followers of a user. The followers_count attribute provides us with an integer donating the number of followers the user account has. Identifying the number of followers in the GUI : In the above mentioned profile the number of followers are : 17.8K (17, 800+) In order to get the number of fo
2 min read
Python | Popup widget in Kivy
Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications. &#128073;&#127997; Kivy Tutorial - Learn Kivy with Examples. Popup widget : The Popup widget is used to create pop
6 min read
Python | Popup widget in Kivy using .kv file
Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications. &#128073;&#127997; Kivy Tutorial - Learn Kivy with Examples. Popup widget: To use popup you must have to import :
4 min read
Popup Menu in Tkinter
Tkinter is Python’s standard GUI (Graphical User Interface) package. It is one of the most commonly used packages for GUI applications which comes with the Python itself. Note: For more information, refer to Python GUI – tkinter Menu Widget Menus are an important part of any GUI. A common use of menus is to provide convenient access to various oper
2 min read
Python - popup menu in wxPython
In this article we are going to know how can we create a popupmenu in wxPython. We will write a code when we click right on screen a popup menu will show up with menu items names as 'one' and 'two'. Syntax : wx.Window.PopupMenu(self, menu, pos) Parameters : ParameterInput TypeDescriptionmenuwx.MenuMenu in popupmenu.pointwx.Pointpoint of popup menu.
1 min read
Scrape a popup using python and selenium
Web scraping is the process of extracting data from websites. It involves programmatically accessing web pages, parsing the HTML or XML content, and extracting the desired information. With the help of libraries like BeautifulSoup, Selenium, or Scrapy in Python, web scraping can be done efficiently. It enables automating data collection, scraping p
3 min read
How to access popup login window in selenium using Python
Many websites use sign-in using social media to make the login process easy for users. In most cases, if the button is clicked then a new popup window is opened where the user has to enter their user credentials. Manually one can switch windows in a browser and enter the required credentials to log in. But in case of unattended web access using a w
3 min read
Download Instagram Posts Using Python Selenium module
In this article, we will learn how we can download Instagram posts of a profile using Python Selenium module. Requirements:Google Chrome or FirefoxChrome driver(For Google Chrome) or Gecko driver(For Mozilla Firefox)Selenium package: It is a powerful tool for controlling a web browser through the program. It is functional for all browsers, works on
7 min read
Like instagram pictures using Selenium | Python
In this article, we will learn how can we like all the pictures of a profile on Instagram without scrolling and manually clicking the buttons. We will be using Selenium to do this task. Packages/Software needed: 1. Python 3 2. Chromedriver compatible with the existing chrome version (download chromedriver) 3. Google chrome 4. Selenium package (pip
3 min read
Practice Tags :
three90RightbarBannerImg