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!")