Open In App

How to scroll down followers popup in Instagram ?

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.






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. 



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.

driver.get("http://www.instagram.com")

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’]”)))

username.clear()
username.send_keys("<Enter_Your_Username")
password.clear()
password.send_keys("<Enter_Your_Password>")

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

driver.get("https://www.instagram.com/geeks_for_geeks/followers/")

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

Below is the full implementation:




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
driver.get("http://www.instagram.com")
  
# 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:


Article Tags :