> ## Documentation Index
> Fetch the complete documentation index at: https://firecrawl-fix-js-response-syntax-highlighting.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Deno Deploy

> 使用 Firecrawl 与 Deno Deploy，在边缘端搜索、抓取并与网页数据交互。

<div id="prerequisites">
  ## 前置条件
</div>

* Deno 1.40+ 或 Deno 2
* 一个 Firecrawl API 密钥 — [免费获取](https://www.firecrawl.dev/app/api-keys)

<div id="setup">
  ## 设置
</div>

创建 `main.ts`：

```typescript theme={null}
import Firecrawl from "npm:firecrawl";

const firecrawl = new Firecrawl({
  apiKey: Deno.env.get("FIRECRAWL_API_KEY"),
});
```

<div id="search-the-web">
  ## 进行网页搜索
</div>

添加一个 `/search` 路由，用于进行网页搜索，并返回包含完整页面内容的结果。

```typescript theme={null}
Deno.serve(async (req) => {
  const url = new URL(req.url);

  if (req.method === "POST" && url.pathname === "/search") {
    const { query } = await req.json();
    const results = await firecrawl.search(query, { limit: 5 });
    return Response.json(results);
  }

  return new Response("Not found", { status: 404 });
});
```

<div id="scrape-a-page">
  ## 抓取网页
</div>

添加 `/scrape` 路由，从任意 URL 提取干净的 Markdown。

```typescript theme={null}
if (req.method === "POST" && url.pathname === "/scrape") {
  const { url: targetUrl } = await req.json();
  const result = await firecrawl.scrape(targetUrl);
  return Response.json(result);
}
```

<div id="interact-with-a-page">
  ## 与页面交互
</div>

添加 `/interact` 路由以控制实时浏览器会话——点击按钮、填写表单并提取动态内容。

```typescript theme={null}
if (req.method === "POST" && url.pathname === "/interact") {
  const result = await firecrawl.scrape("https://www.amazon.com", {
    formats: ["markdown"],
  });
  const scrapeId = result.metadata?.scrapeId;

  await firecrawl.interact(scrapeId, {
    prompt: "Search for iPhone 16 Pro Max",
  });
  const response = await firecrawl.interact(scrapeId, {
    prompt: "Click on the first result and tell me the price",
  });
  console.log(response.output);

  await firecrawl.stopInteraction(scrapeId);
  return Response.json({ output: response.output });
}
```

<div id="run-locally">
  ## 本地运行
</div>

```bash theme={null}
FIRECRAWL_API_KEY=fc-YOUR-API-KEY deno run --allow-net --allow-env main.ts
```

<div id="deploy">
  ## 部署
</div>

安装 Deno Deploy CLI (`deployctl`) 并部署：

```bash theme={null}
deployctl deploy --project=my-scraper main.ts
```

在 Deno Deploy 的 Dashboard 中或通过 CLI 设置环境变量：

```bash theme={null}
deployctl env set FIRECRAWL_API_KEY=fc-YOUR-API-KEY --project=my-scraper
```

<div id="test-it">
  ## 试一试
</div>

```bash theme={null}
curl -X POST https://my-scraper.deno.dev/search \
  -H "Content-Type: application/json" \
  -d '{"query": "firecrawl web scraping"}'
```

<div id="next-steps">
  ## 下一步
</div>

<CardGroup cols={2}>
  <Card title="搜索文档" icon="magnifying-glass" href="/zh/features/search">
    进行网页搜索并获取完整页面内容
  </Card>

  <Card title="抓取文档" icon="file-lines" href="/zh/features/scrape">
    所有抓取选项，包括 formats、actions 和代理
  </Card>

  <Card title="交互文档" icon="hand-pointer" href="/zh/features/interact">
    点击、填写表单并提取动态内容
  </Card>

  <Card title="Node SDK 参考" icon="node" href="/zh/sdks/node">
    完整的 SDK 参考，涵盖爬取、map、batch scrape 等功能
  </Card>
</CardGroup>
