In this article, we are going to be discussing how to automate Instagram using Python and Selenium. Instagram is a social media platform where users can share photos and videos. In this article, we are going to be creating a bot that will like photos on Instagram.
The first thing that we need to do is install the necessary dependencies. We will need Selenium, Python, and the Instagram API. We can install Selenium and Python using pip.
pip install selenium
pip install python
Next, we need to create a file called instagram_bot.py. This file will contain our Python code. The first thing that we need to do is import the necessary modules.
import selenium
import time
Next, we need to create a function that will login to Instagram.
def login(username, password):
driver = selenium.webdriver.Firefox()
driver.get(”
driver.find_element_by_id(“username”).send_keys(username)
driver.find_element_by_id(“password”).send_keys(password)
driver.find_element_by_id(“signin”).click()
return driver
Next, we need to create a function that will like a photo.
def like_photo(photo_id):
driver = selenium.webdriver.Firefox()
driver.get(”
driver.find_element_by_id(“id”).send_keys(photo_id)
driver.find_element_by_css_selector(“.thumbnail”).click()
driver.find_element_by_css_selector(“a.like_button”).click()
return driver
Now that we have our functions, we can write the main() function.
def main():
username = “username”
password = “password”
photo_id = “photo_id”
login(username, password)
like_photo(photo_id)
time.sleep(60)