Geek7 commited on
Commit
96204d9
·
verified ·
1 Parent(s): cbcaa0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -23
app.py CHANGED
@@ -1,33 +1,24 @@
1
  import streamlit as st
2
- from bs4 import BeautifulSoup
3
  import requests
4
- from selenium import webdriver
5
  import time
6
- import io
7
  from PIL import Image
 
8
 
9
  def download_instagram_image(link):
10
- options = webdriver.ChromeOptions()
11
- options.add_argument('--headless')
12
- options.add_argument('--disable-gpu')
13
- options.add_argument('--no-sandbox')
14
-
15
- with webdriver.Chrome('chromedriver', options=options) as driver:
16
- driver.get(link)
17
- time.sleep(2) # Allow time for the page to load
18
 
19
- soup = BeautifulSoup(driver.page_source, 'lxml')
20
- img = soup.find('img', class_='FFVAD')
21
-
22
- if img:
23
- img_url = img['src']
24
- img_data = requests.get(img_url).content
25
-
26
- image = Image.open(io.BytesIO(img_data))
27
- image.save(f"instagram_{int(time.time())}.png")
28
- st.success('Image downloaded successfully!')
29
- else:
30
- st.error('Could not find the image on the provided URL.')
31
 
32
  def main():
33
  st.title("Instagram Image Downloader")
 
1
  import streamlit as st
 
2
  import requests
 
3
  import time
 
4
  from PIL import Image
5
+ from io import BytesIO
6
 
7
  def download_instagram_image(link):
8
+ response = requests.get(link)
9
+
10
+ if response.status_code == 200:
11
+ data = response.json()
12
+ img_url = data["graphql"]["shortcode_media"]["display_url"]
 
 
 
13
 
14
+ img_response = requests.get(img_url)
15
+ img_data = BytesIO(img_response.content)
16
+
17
+ image = Image.open(img_data)
18
+ image.save(f"instagram_{int(time.time())}.png")
19
+ st.success('Image downloaded successfully!')
20
+ else:
21
+ st.error('Error fetching Instagram data. Please check the provided URL.')
 
 
 
 
22
 
23
  def main():
24
  st.title("Instagram Image Downloader")