Scrape 抓取 API(2/2)

doc = firecrawl.scrape('https://example.com', formats=['markdown'], location={ 'country': 'US', 'languages': ['en'] } )

print(doc)


```js
import { Firecrawl } from 'firecrawl';

const firecrawl = new Firecrawl({
  // No API key needed to get started — add one for higher rate limits:
  // apiKey: "fc-YOUR-API-KEY",
});

const doc = await firecrawl.scrape('https://example.com', {
  formats: ['markdown'],
  location: { country: 'US', languages: ['en'] },
});

console.log(doc.metadata);
# No API key needed to get started — add -H "Authorization: Bearer $FIRECRAWL_API_KEY" for higher rate limits:
curl -X POST "https://api.firecrawl.dev/v2/scrape" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "formats": ["markdown"],
    "location": { "country": "US", "languages": ["en"] }
  }'

For more details about supported locations, refer to the Proxies documentation.

Caching and maxAge

To make requests faster, Firecrawl serves results from cache by default when a recent copy is available.

  • Default freshness window: maxAge = 172800000 ms (2 days). If a cached page is newer than this, it’s returned instantly; otherwise, the page is scraped and then cached.
  • Performance: This can speed up scrapes by up to 5x when data doesn’t need to be ultra-fresh.
  • Always fetch fresh: Set maxAge to 0. Note that this bypasses the cache entirely, so every request goes through the full scraping pipeline, meaning that the request will take longer to complete and is more likely to fail. Use a non-zero maxAge if freshness on every request is not critical.
  • Avoid storing: Set storeInCache to false if you don’t want Firecrawl to cache/store results for this request.
  • Cache-only lookup: Set minAge to perform a cache-only lookup without triggering a fresh scrape. The value is in milliseconds and specifies the minimum age the cached data must be. If no cached data is found, a 404 with error code SCRAPE_NO_CACHED_DATA is returned. Set minAge to 1 to accept any cached data regardless of age.
  • Change tracking: Requests that include changeTracking bypass the cache, so maxAge is ignored.
  • Credits: Cached results still cost 1 credit per page. Caching improves speed, not credit usage.

Example (force fresh content):

from firecrawl import Firecrawl
firecrawl = Firecrawl(api_key='fc-YOUR_API_KEY')

doc = firecrawl.scrape(url='https://example.com', max_age=0, formats=['markdown'])
print(doc)
import { Firecrawl } from 'firecrawl';

const firecrawl = new Firecrawl({ apiKey: "fc-YOUR-API-KEY" });

const doc = await firecrawl.scrape('https://example.com', { maxAge: 0, formats: ['markdown'] });
console.log(doc);
curl -s -X POST "https://api.firecrawl.dev/v2/scrape" \
  -H "Authorization: Bearer $FIRECRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "maxAge": 0,
    "formats": ["markdown"]
  }'

Example (use a 10-minute cache window):

from firecrawl import Firecrawl
firecrawl = Firecrawl(api_key='fc-YOUR_API_KEY')

doc = firecrawl.scrape(url='https://example.com', max_age=600000, formats=['markdown', 'html'])
print(doc)

const firecrawl = new Firecrawl({ apiKey: "fc-YOUR-API-KEY" });

const doc = await firecrawl.scrape('https://example.com', { maxAge: 600000, formats: ['markdown', 'html'] });
console.log(doc);
curl -s -X POST "https://api.firecrawl.dev/v2/scrape" \
  -H "Authorization: Bearer $FIRECRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "maxAge": 600000,
    "formats": ["markdown", "html"]
  }'
Freshness and item status

maxAge controls whether Firecrawl may return a cached copy; it does not tell you whether the state represented by a page is current. When freshness matters, use maxAge: 0 to skip the cache, then inspect the returned content and any redirect or source-specific status signals. A successful response alone is not proof of current state.

See Verifying Freshness and Liveness for a checklist and examples.

Alexandria data tools

Scrape can also run a data tool from Alexandria, the Firecrawl catalogue of third-party data providers. Send an alexandria object with provider, capability, and options instead of a url. Get these values from Search or Find Tools.

result = firecrawl.scrape(
    alexandria={
        "provider": "particle",
        "capability": "podcasts/episodes/search",
        "options": {"semantic_search": "AI agents", "limit": 2},
    },
)

print(result.alexandria[0].data)
const result = await firecrawl.scrape({
  alexandria: {
    provider: "particle",
    capability: "podcasts/episodes/search",
    options: { semantic_search: "AI agents", limit: 2 },
  },
});

console.log(result.alexandria[0].data);
curl -X POST https://api.firecrawl.dev/v2/scrape \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer fc-YOUR_API_KEY" \
  -d '{
    "alexandria": {
      "provider": "particle",
      "capability": "podcasts/episodes/search",
      "options": { "semantic_search": "AI agents", "limit": 2 }
    }
  }'
  • The response has one item for each call in data.alexandria. Each item has data or an error. Examine each item, because one call can fail when the request succeeds.
  • Send an array of up to 10 calls to run them in one request. You cannot use alexandria together with url or other scrape options.
  • Each call costs the price listed on its tool. data.creditsCost shows the total.
  • To retry, send the same x-request-id header with the same body. A completed request replays its result and does not run again. Without this header, a retry is a new charge.
  • Some providers need an org admin to accept their terms first. Then the request fails with THIRD_PARTY_DATA_TERMS_REQUIRED.

To find tools for the page that you scrape, add domainTools: true to an ordinary URL scrape. Matching tools come back in data.tools. See Alexandria for pricing and access.

Batch scraping multiple URLs

You can now batch scrape multiple URLs at the same time. It takes the starting URLs and optional parameters as arguments. The params argument allows you to specify additional options for the batch scrape job, such as the output formats.

How it works

It is very similar to how the /crawl endpoint works. It submits a batch scrape job and returns a job ID to check the status of the batch scrape.

The sdk provides 2 methods, synchronous and asynchronous. The synchronous method will return the results of the batch scrape job, while the asynchronous method will return a job ID that you can use to check the status of the batch scrape.

Usage
from firecrawl import Firecrawl

firecrawl = Firecrawl(api_key="fc-YOUR-API-KEY")

job = firecrawl.batch_scrape([
    "https://firecrawl.dev",
    "https://docs.firecrawl.dev",
], formats=["markdown"], poll_interval=2, wait_timeout=120)

print(job)
import { Firecrawl } from 'firecrawl';

const firecrawl = new Firecrawl({ apiKey: "fc-YOUR-API-KEY" });

const job = await firecrawl.batchScrape([
  'https://firecrawl.dev',
  'https://docs.firecrawl.dev',
], { options: { formats: ['markdown'] }, pollInterval: 2, timeout: 120 });

console.log(job);
curl -s -X POST "https://api.firecrawl.dev/v2/batch/scrape" \
  -H "Authorization: Bearer $FIRECRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": ["https://firecrawl.dev", "https://docs.firecrawl.dev"],
    "formats": ["markdown"]
  }'
Response

If you’re using the sync methods from the SDKs, it will return the results of the batch scrape job. Otherwise, it will return a job ID that you can use to check the status of the batch scrape.

Synchronous
{
  "status": "completed",
  "total": 36,
  "completed": 36,
  "creditsUsed": 36,
  "expiresAt": "2024-00-00T00:00:00.000Z",
  "next": "https://api.firecrawl.dev/v2/batch/scrape/123-456-789?skip=26",
  "data": [
    {
      "markdown": "[Firecrawl Docs home page![light logo](https://mintlify.s3-us-west-1.amazonaws.com/firecrawl/logo/light.svg)!...",
      "html": "<!DOCTYPE html><html lang=\"en\" class=\"js-focus-visible lg:[--scroll-mt:9.5rem]\" data-js-focus-visible=\"\">...",
      "metadata": {
        "title": "Build a 'Chat with website' using Groq Llama 3 | Firecrawl",
        "language": "en",
        "sourceURL": "https://docs.firecrawl.dev/learn/rag-llama3",
        "description": "Learn how to use Firecrawl, Groq Llama 3, and Langchain to build a 'Chat with your website' bot.",
        "ogLocaleAlternate": [],
        "statusCode": 200
      }
    },
    ...
  ]
}
Asynchronous

You can then use the job ID to check the status of the batch scrape by calling the /batch/scrape/{id} endpoint. This endpoint is meant to be used while the job is still running or right after it has completed as batch scrape jobs expire after 24 hours.

{
  "success": true,
  "id": "123-456-789",
  "url": "https://api.firecrawl.dev/v2/batch/scrape/123-456-789"
}

Enhanced Mode

For complex websites, Firecrawl offers enhanced mode that provides better success rates while maintaining privacy.

Learn more about Enhanced Mode.

Zero Data Retention (ZDR)

Firecrawl supports Zero Data Retention (ZDR) for teams with strict data handling requirements. When enabled, Firecrawl will not persist any page content or extracted data beyond the lifetime of the request.

To enable ZDR, set zeroDataRetention: true in your request:

curl -X POST https://api.firecrawl.dev/v2/scrape \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer fc-YOUR_API_KEY" \
  -d '{
    "url": "https://example.com",
    "formats": ["markdown"],
    "zeroDataRetention": true
  }'

ZDR is available on Enterprise plans and must be enabled for your team. Visit firecrawl.dev/enterprise to get started.

ZDR adds 1 additional credit per page on top of the base scrape cost.

Screenshots are not available in ZDR mode. Because screenshots require uploading to persistent storage, they are incompatible with the ZDR guarantee. Requests that include both zeroDataRetention: true and a screenshot format will return an error.

Are you an AI agent that needs a Firecrawl API key? See firecrawl.dev/agent-onboarding/SKILL.md for automated onboarding instructions.