Skip to content

Instantly share code, notes, and snippets.

@sevbo2003
Created July 15, 2023 14:22
Show Gist options
  • Save sevbo2003/eb2754d3ded9f8a0e4301ef35d65ca48 to your computer and use it in GitHub Desktop.
Save sevbo2003/eb2754d3ded9f8a0e4301ef35d65ca48 to your computer and use it in GitHub Desktop.
Simple script for scraping instagram post
selenium==4.10.0
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver_path = '/usr/local/bin/'
driver = webdriver.Chrome()
driver.get("https://www.instagram.com")
post_url = "https://www.instagram.com/p/Ctt9iggRrT1/"
driver.get(post_url)
wait = WebDriverWait(driver, 5)
post_author = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "xt0psk2")))
post_title = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "_a9zs")))
post_image = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "x5yr21d")))
post_location = wait.until(EC.presence_of_element_located((By.XPATH, "//div[@class='_aaqm']")))
data = {
"post_author": post_author.text,
"post_title": post_title.text,
"post_image": post_image.get_attribute("src"),
"post_location": post_location.text
}
print(data)
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment