File size: 1,475 Bytes
1d549e9 788fb51 73319d4 788fb51 73319d4 040868d 1d549e9 788fb51 040868d 1d549e9 788fb51 1d549e9 788fb51 73319d4 1d549e9 788fb51 73319d4 788fb51 73319d4 1d549e9 788fb51 1d549e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
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() |