()
| 11 | load_dotenv() |
| 12 | |
| 13 | def main(): |
| 14 | api_key = os.getenv("FIRECRAWL_API_KEY") |
| 15 | if not api_key: |
| 16 | raise ValueError("FIRECRAWL_API_KEY is not set") |
| 17 | |
| 18 | api_url = os.getenv("FIRECRAWL_API_URL") |
| 19 | if not api_url: |
| 20 | raise ValueError("FIRECRAWL_API_URL is not set") |
| 21 | |
| 22 | firecrawl = Firecrawl(api_key=api_key, api_url=api_url) |
| 23 | |
| 24 | # Scrape |
| 25 | doc = firecrawl.scrape("https://docs.firecrawl.dev", formats=["markdown"]) |
| 26 | print("scrape:", doc.markdown) |
| 27 | # doc.metadata_dict is a dict, doc.metadata_typed is a DocumentMetadata object |
| 28 | print(doc.metadata_dict.get("source_url")) |
| 29 | print('metadata_dict.get("title"):', doc.metadata_dict.get("title")) |
| 30 | print("metadata_typed.title:", doc.metadata_typed.title) |
| 31 | print("metadata.title", doc.metadata.title if doc.metadata else None) |
| 32 | |
| 33 | |
| 34 | # Crawl (waits until terminal state) |
| 35 | crawl_job = firecrawl.crawl("https://docs.firecrawl.dev", limit=3, poll_interval=1, timeout=120) |
| 36 | print("crawl:", crawl_job.status, crawl_job.completed, "/", crawl_job.total) |
| 37 | |
| 38 | # Batch scrape |
| 39 | batch = firecrawl.batch_scrape([ |
| 40 | "https://docs.firecrawl.dev", |
| 41 | "https://firecrawl.dev", |
| 42 | ], formats=["markdown"], poll_interval=1, wait_timeout=120) |
| 43 | print("batch:", batch.status, batch.completed, "/", batch.total) |
| 44 | |
| 45 | # Search |
| 46 | search_response = firecrawl.search(query="What is the capital of France?", limit=5) |
| 47 | print("search web results:", len(getattr(search_response, "web", []) or [])) |
| 48 | |
| 49 | # Map |
| 50 | map_response = firecrawl.map("https://firecrawl.dev") |
| 51 | print("map links:", len(getattr(map_response, "links", []) or [])) |
| 52 | |
| 53 | if __name__ == "__main__": |
| 54 | main() |
no test coverage detected
searching dependent graphs…