Spaces:
Running
Running
from .tool import Tool | |
from firecrawl import FirecrawlApp | |
from dotenv import load_dotenv | |
import os | |
load_dotenv() | |
class FirecrawlScrapeTool(Tool): | |
def __init__(self): | |
super().__init__( | |
name="firecrawl_scrape", | |
description="Scrape a website and return the markdownified version of the content", | |
inputSchema={ | |
"type": "object", | |
"properties": { | |
"url": {"type": "string", "description": "The URL to scrape"} | |
} | |
} | |
) | |
def __call__(self, url: str): | |
try: | |
if not url: | |
return "Error: URL parameter is required" | |
app = FirecrawlApp(api_key=os.getenv("FIRECRAWL_API_KEY")) | |
scrape_result = app.scrape_url(url, formats=['markdown', 'html']) | |
return scrape_result["data"]["markdown"] | |
except Exception as e: | |
return f"Error scraping URL: {str(e)}" | |