()
| 14 | |
| 15 | |
| 16 | async def main() -> None: |
| 17 | load_dotenv() |
| 18 | |
| 19 | api_key = os.getenv("FIRECRAWL_API_KEY") |
| 20 | if not api_key: |
| 21 | raise ValueError("FIRECRAWL_API_KEY is not set") |
| 22 | |
| 23 | api_url = os.getenv("FIRECRAWL_API_URL") |
| 24 | if not api_url: |
| 25 | raise ValueError("FIRECRAWL_API_URL is not set") |
| 26 | |
| 27 | client = AsyncFirecrawl(api_key=api_key, api_url=api_url) |
| 28 | |
| 29 | # Scrape (minimal) |
| 30 | doc = await client.v2.scrape("https://docs.firecrawl.dev") |
| 31 | print("scrape markdown:", doc.markdown) |
| 32 | |
| 33 | # Crawl (waiter) |
| 34 | crawl_job = await client.v2.crawl(url="https://docs.firecrawl.dev", limit=2, poll_interval=1, timeout=120) |
| 35 | print("crawl:", crawl_job.status, crawl_job.completed, "/", crawl_job.total) |
| 36 | |
| 37 | # Batch scrape (minimal waiter) |
| 38 | batch = await client.v2.batch_scrape([ |
| 39 | "https://docs.firecrawl.dev", |
| 40 | "https://firecrawl.dev", |
| 41 | ], formats=["markdown"], poll_interval=1, timeout=180) |
| 42 | print("batch:", batch.status, batch.completed, "/", batch.total) |
| 43 | |
| 44 | # Search (minimal) |
| 45 | search = await client.v2.search("What is the capital of France?", limit=5) |
| 46 | web_count = len(getattr(search, "web", []) or []) if hasattr(search, "web") else len(getattr(search, "results", []) or []) |
| 47 | print("search web results:", web_count) |
| 48 | |
| 49 | # Map (minimal) |
| 50 | mp = await client.v2.map("https://firecrawl.dev") |
| 51 | links = getattr(mp, "links", []) or [] |
| 52 | print("map links:", len(links)) |
| 53 | |
| 54 | |
| 55 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…