Skip to content

ScrapeGraphAI

ScrapeGraphAI MCP 服务器将你的 ADK 智能体连接到 ScrapeGraphAI。此集成使你的智能体能够使用自然语言提示提取结构化数据、处理无限滚动等动态内容,并将复杂的网页转换为干净、可用的 JSON 或 Markdown。

使用场景

  • 可扩展的提取和爬取:从单个页面提取结构化数据或爬取整个网站,利用 AI 处理动态内容、无限滚动和大规模异步操作。

  • 研究和摘要:执行 AI 驱动的网络搜索来研究主题、聚合来自多个来源的数据并总结发现。

  • 智能体工作流程:运行高级智能体抓取工作流程,具有可自定义的步骤、复杂的导航(如身份验证)和结构化输出架构。

前提条件

与智能体一起使用

from google.adk.agents import Agent
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
from mcp import StdioServerParameters

SGAI_API_KEY = "YOUR_SCRAPEGRAPHAI_API_KEY"

root_agent = Agent(
    model="gemini-2.5-pro",
    name="scrapegraph_assistant_agent",
    instruction="""使用 ScrapeGraph AI 帮助用户进行网页抓取和数据提取。
                  你可以将网页转换为 markdown、使用 AI 提取结构化数据、
                  执行网络搜索、爬取多个页面并自动化复杂的抓取工作流程。""",
    tools=[
        MCPToolset(
            connection_params=StdioConnectionParams(
                server_params=StdioServerParameters(
                    # 以下 CLI 命令可从 `pip install scrapegraph-mcp` 获得
                    command="scrapegraph-mcp",
                    env={
                        "SGAI_API_KEY": SGAI_API_KEY,
                    },
                ),
                timeout=300,
            ),
        # 可选:过滤从 MCP 服务器公开的工具
        # tool_filter=["markdownify", "smartscraper", "searchscraper"]
        ),
    ],
)

可用工具

工具 描述
markdownify 将任何网页转换为干净、结构化的 markdown 格式
smartscraper 利用 AI 从任何网页提取结构化数据,支持无限滚动
searchscraper 执行 AI 驱动的网络搜索,提供结构化、可操作的结果
scrape 基本抓取端点,用于获取页面内容,可选择渲染复杂的 JavaScript
sitemap 提取任何网站的站点地图 URL 和结构
smartcrawler_initiate 启动智能多页面网络爬取(异步操作)
smartcrawler_fetch_results 从异步爬取操作中检索结果
agentic_scrapper 运行高级智能体抓取工作流程,具有可自定义的步骤和结构化输出架构

其他资源