Dl4 / app.py
Geek7's picture
Update app.py
040868d verified
raw
history blame
1.48 kB
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) # Allow time for the page to load
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")
# Input field for Instagram post URL
link = st.text_input("Enter Instagram Image URL:")
# Button to trigger the download
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()