Created
July 15, 2023 14:22
-
-
Save sevbo2003/eb2754d3ded9f8a0e4301ef35d65ca48 to your computer and use it in GitHub Desktop.
Simple script for scraping instagram post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
selenium==4.10.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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