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

# ScrapeGraph

> Agno ScrapeGraphTools 使智能体能够从网页中提取结构化数据，并以 markdown 格式提供给 LLM。

## 前提条件

以下示例需要 `scrapegraph-py` 库。

```shell theme={null}
pip install -U scrapegraph-py
```

如果您的 ScrapeGraph 配置或特定模型需要 API 密钥，请设置 `SGAI_API_KEY` 环境变量：

```shell theme={null}
export SGAI_API_KEY="YOUR_SGAI_API_KEY"
```

## 示例

下面的智能体使用 `ScrapeGraphTools` 通过 `smartscraper` 功能从网页中提取特定信息。

```python theme={null}
from agno.agent import Agent
from agno.tools.scrapegraph import ScrapeGraphTools

agent = Agent(
    tools=[ScrapeGraphTools(smartscraper=True)],
    show_tool_calls=True,
)

agent.print_response("""
    "使用 smartscraper 从 https://www.wired.com/category/science/ 提取以下信息：
- 新闻文章
- 标题
- 图片
- 链接
- 作者
""",
)
```

<Note>查看 [Startup Analyst 示例](/examples/agents/startup-analyst-agent) </Note>

## Toolkit Functions

| Function       | Description                                  |
| -------------- | -------------------------------------------- |
| `smartscraper` | 使用 LLM 和自然语言提示从网页中提取结构化数据。返回结果的 JSON 字符串或错误。 |
| `markdownify`  | 将网页转换为 markdown 格式。返回 markdown 字符串或错误。       |

## Toolkit 参数

这些参数将传递给 `ScrapeGraphTools` 构造函数。

| Parameter      | Type            | Default | Description                                            |
| -------------- | --------------- | ------- | ------------------------------------------------------ |
| `api_key`      | `Optional[str]` | `None`  | ScrapeGraph 服务的 API 密钥。如果未提供，将默认为 `SGAI_API_KEY` 环境变量。 |
| `smartscraper` | `bool`          | `True`  | 启用 `smartscraper` 工具。                                  |
| `markdownify`  | `bool`          | `False` | 启用 `markdownify` 工具。                                   |

## Developer Resources

* 查看 [Tools Source](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/scrapegraph.py)
* 查看 [Cookbook Example](https://github.com/agno-agi/agno/blob/main/cookbook/tools/scrapegraph_tools.py)
