前提条件
以下示例需要scrapegraph-py 库。
SGAI_API_KEY 环境变量:
示例
下面的智能体使用ScrapeGraphTools 通过 smartscraper 功能从网页中提取特定信息。
Toolkit Functions
Toolkit 参数
这些参数将传递给ScrapeGraphTools 构造函数。
Developer Resources
- 查看 Tools Source
- 查看 Cookbook Example
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Agno ScrapeGraphTools 使智能体能够从网页中提取结构化数据,并以 markdown 格式提供给 LLM。
scrapegraph-py 库。
pip install -U scrapegraph-py
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/ 提取以下信息:
- 新闻文章
- 标题
- 图片
- 链接
- 作者
""",
)
| Function | Description |
|---|---|
smartscraper | 使用 LLM 和自然语言提示从网页中提取结构化数据。返回结果的 JSON 字符串或错误。 |
markdownify | 将网页转换为 markdown 格式。返回 markdown 字符串或错误。 |
ScrapeGraphTools 构造函数。
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | Optional[str] | None | ScrapeGraph 服务的 API 密钥。如果未提供,将默认为 SGAI_API_KEY 环境变量。 |
smartscraper | bool | True | 启用 smartscraper 工具。 |
markdownify | bool | False | 启用 markdownify 工具。 |