Panduan Pengoptimuman Credit
Minimumkan kos scraping dengan memilih alat yang betul, melaksanakan strategi cache yang pintar, dan mengoptimumkan aliran kerja anda untuk nilai maksimum.
Kemenangan Pantas (Jimat 50-80%)
💰 80% pengurangan kos
fetch_url (1 credit) sebelum scrape_with_actions (5 credits)💰 80% pengurangan kos untuk kandungan statik
💰 90%+ pengurangan untuk permintaan berulang
⚡ throughput 5x lebih pantas
1. Strategi Pemilihan Alat
Sentiasa mulakan dengan alat termurah yang memenuhi keperluan anda, kemudian naik taraf hanya jika perlu.
- 1. Adakah anda tahu URL?
- ✅ Ya → Gunakan
fetch_url(1 credit) - ❌ Tidak → Gunakan
search_web(5 credits)
- ✅ Ya → Gunakan
- 2. Adakah kandungan dalam HTML awal?
- ✅ Ya → Gunakan
fetch_url(1 credit) + hurai secara setempat (percuma) - ❌ Tidak (dipaparkan JavaScript) → Gunakan
scrape_with_actions(5 credits)
- ✅ Ya → Gunakan
- 3. Adakah anda perlukan ekstraksi berstruktur?
- ✅ Ya → Gunakan
scrape_structured(2 credits) - ❌ Tidak (HTML mentah sudah memadai) → Gunakan
fetch_url(1 credit)
- ✅ Ya → Gunakan
- 4. Adakah anda perlukan penyelidikan berkuasa AI?
- ✅ Ya → Gunakan
deep_research(10 credits) - ❌ Tidak → Gunakan alternatif yang lebih murah
- ✅ Ya → Gunakan
Perbandingan Kos mengikut Kes Penggunaan
| Kes Penggunaan | Alat Salah | Alat Betul | Penjimatan |
|---|---|---|---|
| Ambil HTML | search_web (5) | fetch_url (1) | 80% |
| Ekstrak teks | scrape_with_actions (5) | extract_text (1) | 80% |
| Dapatkan metadata | scrape_structured (2) | extract_metadata (1) | 50% |
| Selidik topik | deep_research (10) | search_web (5) + fetch_url (1×3) | 20% |
Contoh: Mengekstrak Data Produk
Salah (10 credits)
// 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 💸Betul (2 credits)
// 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. Strategi Cache
Elakkan scraping semula kandungan yang sama dengan melaksanakan cache yang pintar.
Contoh Cache Redis
Cache keputusan selama 24 jam untuk menghapuskan permintaan berganda
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)3. Permintaan Kelompok lwn Individu
Gunakan pemprosesan kelompok untuk berbilang URL bagi meningkatkan throughput dan mengurangkan overhed.
- Permintaan Individu
- ⏱️ Masa: ~5 saat setiap URL
- 💰 Kos: 1 credit setiap URL
- 📊 Throughput: 12 URL/minit
- Guna untuk: <10 URL
- Permintaan Kelompok (Disyorkan)
- ⏱️ Masa: ~15 saat untuk 50 URL
- 💰 Kos: 1 credit setiap URL
- 📊 Throughput: 200 URL/minit
- ✅ Guna untuk: 10+ URL (16x lebih pantas!)
Perbandingan Kod
// 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 credits4. Analisis Kos/Faedah
Kira ROI bagi operasi scraping anda.
1,000 credits percubaan sekali sahaja — = 1,000 permintaan fetch_url
5,000 credits — = $0.0038/credit
50,000 credits — = $0.002/credit
Kos Setiap 1,000 URL (Hobby Plan)
- ✅ Menggunakan
fetch_url(1 credit): $3.80 - ⚠️ Menggunakan
scrape_structured(2 credits): $7.60 - ❌ Menggunakan
scrape_with_actions(5 credits): $19.00 - ❌ Menggunakan
deep_research(10 credits): $38.00
Ringkasan Pengoptimuman
- Sentiasa mulakan dengan
fetch_url - Cache keputusan untuk sekurang-kurangnya 1 jam
- Gunakan
batch_scrapeuntuk 10+ URL - Elakkan
deep_researchuntuk tugas mudah - Hurai HTML secara setempat apabila boleh
- Gunakan
onlyMainContent: trueuntuk scraping kelompok - Jangan scrape URL yang sama dua kali dalam 24j
- Semak sama ada tapak mempunyai API sebelum scraping
- Gunakan webhook untuk kelompok besar (100+ URL)
- Pantau papan pemuka penggunaan setiap minggu