Select a Subtopic
📅 Day 1: Setting up Selenium and WebDriver for Instagram Automation
On Day 1, we will:
- ✅ Install Selenium
- ✅ Set up WebDriver (ChromeDriver)
- ✅ Write your first script to open Instagram in a browser
🛠️ Step 1: Install Selenium
First, install Selenium using pip.
pip install selenium
🛠️ Step 2: Download ChromeDriver
Since Selenium needs a WebDriver to interact with a browser, we need to download ChromeDriver.
➡️ Steps to Download ChromeDriver:
- Go to https://chromedriver.chromium.org/downloads.
- Download the version that matches your Google Chrome version.
- Place the
chromedriver.exe
file in a known directory (e.g.,C:\WebDrivers\chromedriver.exe
).
🛠️ Step 3: Write Your First Selenium Script
We will write a script to:
- Open Instagram in the browser.
- Maximize the browser window.
- Wait for 5 seconds before closing the browser.
📄 Code: Open Instagram using Selenium
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time
# Path to your ChromeDriver
service = Service("C:/WebDrivers/chromedriver.exe")
# Initialize WebDriver
driver = webdriver.Chrome(service=service)
# Open Instagram
driver.get("https://www.instagram.com")
# Maximize the window
driver.maximize_window()
# Wait for 5 seconds
time.sleep(5)
# Close the browser
driver.quit()
✅ Explanation:
webdriver.Chrome(service=service)
: Initializes the Chrome browser using the ChromeDriver.driver.get("https://www.instagram.com")
: Opens Instagram in the browser.driver.maximize_window()
: Maximizes the browser window.time.sleep(5)
: Pauses the script for 5 seconds.driver.quit()
: Closes the browser and ends the session.
🛠️ Step 4: Running the Script
Follow these steps to run your script:
- Save the script as
instagram_bot.py
. - Open your terminal or command prompt.
- Run the script:
python instagram_bot.py
📝 Your Task for Today:
- Install Selenium and download ChromeDriver.
- Write and run the script to open Instagram in your browser.
- Ensure the browser opens, maximizes, and closes after 5 seconds.
💬 Let me know if you encounter any issues! Once you're done, I'll guide you through Day 2: Locating Elements on Instagram. 😊