Documentation Index
Fetch the complete documentation index at: https://student-213fb9fc.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Firecrawl 提供不同类型的代理服务,帮助你抓取不同复杂度的网站。可以使用 proxy 参数指定代理类型。
Firecrawl 支持三种代理类型:
- basic:适用于抓取大多数站点的代理。速度快,通常能正常工作。
- enhanced:用于在保持隐私的前提下抓取复杂站点的增强型代理。速度较慢,但在某些站点上更可靠。
- auto:如果使用 basic 代理抓取失败,Firecrawl 会自动切换为 enhanced 代理并重试抓取。如果使用 enhanced 重试成功,该次抓取将计费 5 个积分;如果首次使用 basic 即成功,则仅按常规费用计费。
如果你未指定代理,Firecrawl 将默认使用 auto。
在抓取复杂网站时,你可以使用增强模式(enhanced mode),在提高成功率的同时保护隐私。
from firecrawl import Firecrawl
firecrawl = Firecrawl(api_key='fc-YOUR-API-KEY')
# 选择代理类型:'basic' | 'enhanced' | 'auto'
doc = firecrawl.scrape('https://example.com', formats=['markdown'], proxy='auto')
print(doc.warning or 'ok')
注意: 使用增强代理时,每个请求会消耗 5 点额度。
一种常见模式是先使用默认代理设置进行抓取,如果在响应的 metadata.statusCode 字段中遇到特定错误状态码(401、403 或 500),再使用 enhanced 模式重试。这些状态码可能表明网站正在阻止你的请求。
# 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"收到状态码 {status_code},改用 enhanced 代理重试")
# Retry with enhanced proxy
content = firecrawl.scrape("https://example.com", proxy="enhanced")
print(content["markdown"])
except Exception as e:
print(f"Error: {e}")
# Retry with enhanced proxy on exception
try:
content = firecrawl.scrape("https://example.com", proxy="enhanced")
print(content["markdown"])
except Exception as e:
print(f"Enhanced proxy also failed: {e}")
这种方法可以让你通过仅在必要时使用 enhanced 模式来优化额度的使用。