> ## 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.

# Python

> 使用 Python 快速上手 Firecrawl。通过官方 SDK 抓取、搜索网页数据并与之交互。

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

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

<div id="install-the-sdk">
  ## 安装 SDK
</div>

```bash theme={null}
pip install firecrawl-py
```

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

```python theme={null}
from firecrawl import Firecrawl

app = Firecrawl(api_key="fc-YOUR-API-KEY")
results = app.search("firecrawl web scraping", limit=5)

for result in results.web:
    print(result.title, result.url)
```

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

```python theme={null}
result = app.scrape("https://example.com")
print(result.markdown)
```

<Accordion title="示例响应">
  ```json theme={null}
  {
    "markdown": "# Example Domain\n\nThis domain is for use in illustrative examples...",
    "metadata": {
      "title": "Example Domain",
      "sourceURL": "https://example.com"
    }
  }
  ```
</Accordion>

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

使用交互功能来控制实时浏览器会话——点击按钮、填写表单并提取动态内容。

```python theme={null}
result = app.scrape("https://www.amazon.com", formats=["markdown"])
scrape_id = result.metadata.scrape_id

app.interact(scrape_id, prompt="Search for iPhone 16 Pro Max")
response = app.interact(scrape_id, prompt="Click on the first result and tell me the price")
print(response.output)

app.stop_interaction(scrape_id)
```

<div id="environment-variable">
  ## 环境变量
</div>

不要直接传入 `api_key`，请改为设置 `FIRECRAWL_API_KEY` 环境变量：

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

```python theme={null}
app = Firecrawl()
```

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

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

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

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

  <Card title="Python SDK 参考" icon="python" href="/zh/sdks/python">
    包含爬取、map、async 等内容的完整 SDK 参考
  </Card>
</CardGroup>
