|
import streamlit as st |
|
from bs4 import BeautifulSoup |
|
import requests |
|
from selenium import webdriver |
|
import time |
|
import io |
|
from PIL import Image |
|
|
|
def download_instagram_image(link): |
|
options = webdriver.ChromeOptions() |
|
options.add_argument('--headless') |
|
options.add_argument('--disable-gpu') |
|
options.add_argument('--no-sandbox') |
|
|
|
with webdriver.Chrome('chromedriver', options=options) as driver: |
|
driver.get(link) |
|
time.sleep(2) |
|
|
|
soup = BeautifulSoup(driver.page_source, 'lxml') |
|
img = soup.find('img', class_='FFVAD') |
|
|
|
if img: |
|
img_url = img['src'] |
|
img_data = requests.get(img_url).content |
|
|
|
image = Image.open(io.BytesIO(img_data)) |
|
image.save(f"instagram_{int(time.time())}.png") |
|
st.success('Image downloaded successfully!') |
|
else: |
|
st.error('Could not find the image on the provided URL.') |
|
|
|
def main(): |
|
st.title("Instagram Image Downloader") |
|
|
|
|
|
link = st.text_input("Enter Instagram Image URL:") |
|
|
|
|
|
if st.button("Download Image"): |
|
if link: |
|
try: |
|
download_instagram_image(link) |
|
except Exception as e: |
|
st.error(f"Error: {str(e)}") |
|
else: |
|
st.warning("Please enter a valid Instagram image URL.") |
|
|
|
if __name__ == "__main__": |
|
main() |