File size: 1,098 Bytes
a1186e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a7f0bb
a1186e0
 
 
7a7f0bb
a1186e0
 
 
 
 
 
b221c36
a1186e0
 
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
import streamlit as st
from firecrawl import FirecrawlApp

# Streamlit UI
st.title("Web Scraper using Firecrawl API")
st.markdown("Enter a URL to scrape its content:")

# User input
api_key = st.text_input("Enter Firecrawl API Key:", type="password")
url = st.text_input("Enter URL:")
format_option = st.selectbox("Select Output Format:", ["plain_text", "markdown", "json"])  # Format selection

# Scraping function
def scrape_website(api_key, url, format_option):
    try:
        app = FirecrawlApp(api_key=api_key)
        response = app.scrape_url(url=url, params={'formats': [format_option]})
        return response.get('content', str(response))  # Get the content if available
    except Exception as e:
        return str(e)


# Button to trigger scraping
if st.button("Scrape Website"):
    if api_key and url:
        with st.spinner("Scraping..."):
            result = scrape_website(api_key, url, format_option)
            st.subheader("Scraped Content:")
            st.text_area("Response:", str(result), height=300)
    else:
        st.error("Please enter both API key and URL!")