前提条件

以下示例需要 scrapegraph-py 库。

pip install -U scrapegraph-py

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

export SGAI_API_KEY="YOUR_SGAI_API_KEY"

示例

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

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/ 提取以下信息:
- 新闻文章
- 标题
- 图片
- 链接
- 作者
""",
)

Toolkit Functions

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

Toolkit 参数

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

ParameterTypeDefaultDescription
api_keyOptional[str]NoneScrapeGraph 服务的 API 密钥。如果未提供,将默认为 SGAI_API_KEY 环境变量。
smartscraperboolTrue启用 smartscraper 工具。
markdownifyboolFalse启用 markdownify 工具。

Developer Resources