CrawlForge
入门指南

Credit 优化指南

通过选择合适的工具、实施智能缓存策略并优化工作流,降低抓取成本,实现最大价值。

工具选择策略
缓存策略
批量 vs 单独
成本/收益分析

快速见效(节省 50-80%)

已知 URL 时使用 fetch_url 而非 search_web
每次请求节省 4 credits(1 credit vs 5 credits)

💰 成本降低 80%

在浏览器自动化之前先尝试静态抓取
先用 fetch_url(1 credit)再用 scrape_with_actions(5 credits)

💰 静态内容成本降低 80%

在本地缓存结果
将抓取的数据存储在 Redis/数据库中,避免重复抓取相同的 URL

💰 重复请求降低 90%+

对多个 URL 使用 batch_scrape
成本相同(每个 URL 1 credit),但比单独请求更快、更高效

⚡ 吞吐量提升 5 倍

1. 工具选择策略

始终从满足需求的最便宜工具开始,仅在必要时升级。

  • 1. 你知道 URL 吗?
    • ✅ 知道 → 使用 fetch_url(1 credit)
    • ❌ 不知道 → 使用 search_web(5 credits)
  • 2. 内容是否在初始 HTML 中?
    • ✅ 是 → 使用 fetch_url(1 credit)+ 在本地解析(免费)
    • ❌ 否(JavaScript 渲染)→ 使用 scrape_with_actions(5 credits)
  • 3. 你需要结构化提取吗?
    • ✅ 需要 → 使用 scrape_structured(2 credits)
    • ❌ 不需要(原始 HTML 即可)→ 使用 fetch_url(1 credit)
  • 4. 你需要 AI 驱动的研究吗?
    • ✅ 需要 → 使用 deep_research(10 credits)
    • ❌ 不需要 → 使用更便宜的替代方案

按使用场景的成本对比

使用场景错误的工具正确的工具节省
抓取 HTMLsearch_web(5)fetch_url(1)80%
提取文本scrape_with_actions(5)extract_text(1)80%
获取元数据scrape_structured(2)extract_metadata(1)50%
研究主题deep_research(10)search_web(5)+ fetch_url(1×3)20%

示例:提取产品数据

错误(10 credits)

Typescript
// Using deep_research for simple task
const response = await fetch(
  'https://crawlforge.dev/api/v1/tools/deep_research',
  {
    method: 'POST',
    headers: {
      'X-API-Key': apiKey,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      topic: 'Product details',
      sources: ['https://shop.com/product/123']
    })
  }
);

// Cost: 10 credits 💸

正确(2 credits)

Typescript
// Using scrape_structured for known URL
const response = await fetch(
  'https://crawlforge.dev/api/v1/tools/scrape_structured',
  {
    method: 'POST',
    headers: {
      'X-API-Key': apiKey,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      url: 'https://shop.com/product/123',
      selectors: {
        title: 'h1.product-name',
        price: 'span.price'
      }
    })
  }
);

// Cost: 2 credits ✅ (80% savings)

2. 缓存策略

通过实施智能缓存,避免重复抓取相同内容。

Redis 缓存示例

将结果缓存 24 小时,消除重复请求

Typescript
import Redis from 'ioredis';

const redis = new Redis(process.env.REDIS_URL!);

async function fetchWithCache(url: string) {
  // Try cache first
  const cacheKey = `scrape:${url}`;
  const cached = await redis.get(cacheKey);

  if (cached) {
    console.log('Cache hit! Saved 1 credit ✅');
    return JSON.parse(cached);
  }

  // Cache miss - scrape the URL
  console.log('Cache miss - scraping...');
  const response = await fetch('https://crawlforge.dev/api/v1/tools/fetch_url', {
    method: 'POST',
    headers: {
      'X-API-Key': process.env.CRAWLFORGE_API_KEY!,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ url }),
  });

  const data = await response.json();

  // Cache for 24 hours
  await redis.setex(cacheKey, 86400, JSON.stringify(data));

  return data;
}

// Usage
const data1 = await fetchWithCache('https://example.com'); // Uses 1 credit
const data2 = await fetchWithCache('https://example.com'); // Uses 0 credits (cached)
const data3 = await fetchWithCache('https://example.com'); // Uses 0 credits (cached)

// Savings: 2 credits (66% reduction)
缓存 TTL 策略: 静态内容(24 小时以上)、产品页面(6 小时)、新闻(1 小时)、实时数据(5 分钟或跳过缓存)

3. 批量 vs 单独请求

对多个 URL 使用批量处理,以提高吞吐量并减少开销。

  • 单独请求
    • ⏱️ 时间:每个 URL 约 5 秒
    • 💰 成本:每个 URL 1 credit
    • 📊 吞吐量:12 个 URL/分钟
    • 适用于:少于 10 个 URL
  • 批量请求(推荐)
    • ⏱️ 时间:50 个 URL 约 15 秒
    • 💰 成本:每个 URL 1 credit
    • 📊 吞吐量:200 个 URL/分钟
    • ✅ 适用于:10 个以上 URL(快 16 倍!)

代码对比

Typescript
// Individual requests (SLOW)
const urls = [...]; // 50 URLs

const results = [];
for (const url of urls) {
  const response = await fetch('https://crawlforge.dev/api/v1/tools/fetch_url', {
    method: 'POST',
    headers: {
      'X-API-Key': process.env.CRAWLFORGE_API_KEY!,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ url }),
  });

  const data = await response.json();
  results.push(data);
}

// Time: ~250 seconds (4+ minutes)
// Cost: 50 credits

4. 成本/收益分析

计算抓取操作的投资回报率。

Free 套餐
$0

1,000 个一次性试用 credits — = 1,000 次 fetch_url 请求

Hobby 套餐
$19

5,000 credits — = $0.0038/credit

Professional
$99

50,000 credits — = $0.002/credit

每 1,000 个 URL 的成本(Hobby 套餐)

  • ✅ 使用 fetch_url(1 credit):$3.80
  • ⚠️ 使用 scrape_structured(2 credits):$7.60
  • ❌ 使用 scrape_with_actions(5 credits):$19.00
  • ❌ 使用 deep_research(10 credits):$38.00

优化总结

  1. 始终从 fetch_url 开始
  2. 将结果至少缓存 1 小时
  3. 对 10 个以上 URL 使用 batch_scrape
  4. 对简单任务避免使用 deep_research
  5. 尽可能在本地解析 HTML
  6. 批量抓取时使用 onlyMainContent: true
  7. 24 小时内不要重复抓取同一 URL
  8. 抓取前检查站点是否提供 API
  9. 对大批量任务(100+ URL)使用 webhook
  10. 每周监控用量控制台
准备好优化了吗?
开始实施这些策略,将成本降低 50-80%
查看 API 参考查看定价