gskdsrikrishna commited on
Commit
2fb4206
Β·
verified Β·
1 Parent(s): d89d5ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -13,6 +13,20 @@ HEADERS = {
13
  "x-rapidapi-host": "instagram-scraper-api2.p.rapidapi.com"
14
  }
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  # Streamlit UI
17
  st.set_page_config(page_title="Instagram Scraper", layout="wide")
18
  st.title("πŸ“Έ Instagram Scraper API")
@@ -32,8 +46,8 @@ if st.button("Fetch Details"):
32
  st.subheader("πŸ“œ JSON Response")
33
  st.json(data)
34
 
35
- # Extracting Links
36
- links = [value for key, value in data.items() if isinstance(value, str) and value.startswith("http")]
37
 
38
  # Display Links Below JSON
39
  if links:
@@ -41,7 +55,7 @@ if st.button("Fetch Details"):
41
  for link in links:
42
  st.markdown(f"[πŸ”— {link}]({link})")
43
  else:
44
- st.info("No links found in the response.")
45
 
46
  # **Download Buttons Below Links**
47
  st.subheader("⬇️ Download Data")
 
13
  "x-rapidapi-host": "instagram-scraper-api2.p.rapidapi.com"
14
  }
15
 
16
+ # Function to extract all links recursively from JSON
17
+ def extract_links(obj):
18
+ links = []
19
+ if isinstance(obj, dict):
20
+ for key, value in obj.items():
21
+ if isinstance(value, str) and value.startswith("http"):
22
+ links.append(value)
23
+ elif isinstance(value, (dict, list)):
24
+ links.extend(extract_links(value))
25
+ elif isinstance(obj, list):
26
+ for item in obj:
27
+ links.extend(extract_links(item))
28
+ return links
29
+
30
  # Streamlit UI
31
  st.set_page_config(page_title="Instagram Scraper", layout="wide")
32
  st.title("πŸ“Έ Instagram Scraper API")
 
46
  st.subheader("πŸ“œ JSON Response")
47
  st.json(data)
48
 
49
+ # Extracting Links from Nested JSON
50
+ links = extract_links(data)
51
 
52
  # Display Links Below JSON
53
  if links:
 
55
  for link in links:
56
  st.markdown(f"[πŸ”— {link}]({link})")
57
  else:
58
+ st.info("❌ No links found in the response.")
59
 
60
  # **Download Buttons Below Links**
61
  st.subheader("⬇️ Download Data")