Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from firecrawl import FirecrawlApp
|
3 |
+
|
4 |
+
# Streamlit UI
|
5 |
+
st.title("Web Scraper using Firecrawl API")
|
6 |
+
st.markdown("Enter a URL to scrape its content:")
|
7 |
+
|
8 |
+
# User input
|
9 |
+
api_key = st.text_input("Enter Firecrawl API Key:", type="password")
|
10 |
+
url = st.text_input("Enter URL:")
|
11 |
+
format_option = st.selectbox("Select Output Format:", ["plain_text", "markdown", "json"]) # Format selection
|
12 |
+
|
13 |
+
# Scraping function
|
14 |
+
def scrape_website(api_key, url, format_option):
|
15 |
+
try:
|
16 |
+
app = FirecrawlApp(api_key=api_key)
|
17 |
+
response = app.scrape_url(url=url, params={'formats': [format_option]})
|
18 |
+
return response
|
19 |
+
except Exception as e:
|
20 |
+
return str(e)
|
21 |
+
|
22 |
+
# Button to trigger scraping
|
23 |
+
if st.button("Scrape Website"):
|
24 |
+
if api_key and url:
|
25 |
+
with st.spinner("Scraping..."):
|
26 |
+
result = scrape_website(api_key, url, format_option)
|
27 |
+
st.subheader("Scraped Content:")
|
28 |
+
st.text_area("Response:", result, height=300)
|
29 |
+
else:
|
30 |
+
st.error("Please enter both API key and URL!")
|