# pip install firecrawl-py
from firecrawl import Firecrawl
firecrawl = Firecrawl(api_key="YOUR_API_KEY")
# First try with basic proxy
try:
    content = firecrawl.scrape("https://example.com")
    
    # Check if we got an error status code
    status_code = content.get("metadata", {}).get("statusCode")
    if status_code in [401, 403, 500]:
        print(f"Got status code {status_code}, retrying with stealth proxy")
        # Retry with stealth proxy
        content = firecrawl.scrape("https://example.com", proxy="stealth")
    
    print(content["markdown"])
except Exception as e:
    print(f"Error: {e}")
    # Retry with stealth proxy on exception
    try:
        content = firecrawl.scrape("https://example.com", proxy="stealth")
        print(content["markdown"])
    except Exception as e:
        print(f"Stealth proxy also failed: {e}")