> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firecrawl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Hono

> 使用 Firecrawl 与 Hono 构建可在任何环境中运行的轻量级网页抓取和搜索 API。

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

* Node.js 18+、Bun 或 Deno
* Firecrawl API 密钥 — [免费获取](https://www.firecrawl.dev/app/api-keys)

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

```bash theme={null}
npm install hono firecrawl
```

将你的 API 密钥添加到 `.env` 文件中：

```bash theme={null}
FIRECRAWL_API_KEY=fc-YOUR-API-KEY
```

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

```typescript theme={null}
import { Hono } from "hono";
import { Firecrawl } from "firecrawl";

const app = new Hono();
const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

app.post("/search", async (c) => {
  const { query } = await c.req.json();
  const results = await firecrawl.search(query, { limit: 5 });
  return c.json(results);
});

export default app;
```

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

```typescript theme={null}
app.post("/scrape", async (c) => {
  const { url } = await c.req.json();
  const result = await firecrawl.scrape(url);
  return c.json(result);
});
```

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

使用 interact 控制实时浏览器会话，可点击按钮、填写表单并提取动态内容。

```typescript theme={null}
app.post("/interact", async (c) => {
  const { url } = await c.req.json();

  const result = await firecrawl.scrape(url, { 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' });

  await firecrawl.stopInteraction(scrapeId);

  return c.json({ output: response.output });
});
```

<div id="deploy-anywhere">
  ## 可部署到任意环境
</div>

Hono 支持在多种运行时中运行。对于 Cloudflare Workers，请通过环境绑定传入 API 密钥：

```typescript theme={null}
import { Hono } from "hono";
import { Firecrawl } from "firecrawl";

type Bindings = { FIRECRAWL_API_KEY: string };
const app = new Hono<{ Bindings: Bindings }>();

app.post("/search", async (c) => {
  const firecrawl = new Firecrawl({ apiKey: c.env.FIRECRAWL_API_KEY });
  const { query } = await c.req.json();
  const results = await firecrawl.search(query, { limit: 5 });
  return c.json(results);
});

export default app;
```

<div id="next-steps">
  ## 后续步骤
</div>

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

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

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

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