FirecrawlAgent-基于MCP的高级网络爬虫


文档摘要

Firecrawl Agent - 基于MCP的高级网络爬虫 欢迎使用Firecrawl MCP Agent!这款强大的代理展示了如何通过模型上下文协议(MCP)将Firecrawl的高级网络爬虫功能与Google ADK集成。 您将学到的内容 Firecrawl集成:连接到Firecrawl全面的网络爬虫平台 高级网络爬虫:单页面、批量处理和全网站爬取 AI驱动的数据提取:利用大语言模型从网页内容中提取结构化数据 研究能力:进行多源分析的深度网络研究 实际应用:数据提取与研究的实用案例 核心功能 全面工具集 单页面爬虫:从单个URL中提取内容,支持高级选项 批量处理:高效地并行爬取多个URL 网站映射:发现网站上的所有URL以供探索 网络搜索:搜索网络并从结果中提取内容

Firecrawl Agent - 基于MCP的高级网络爬虫

欢迎使用Firecrawl MCP Agent!这款强大的代理展示了如何通过模型上下文协议(MCP)将Firecrawl的高级网络爬虫功能与Google ADK集成。

您将学到的内容

  • Firecrawl集成:连接到Firecrawl全面的网络爬虫平台
  • 高级网络爬虫:单页面、批量处理和全网站爬取
  • AI驱动的数据提取:利用大语言模型从网页内容中提取结构化数据
  • 研究能力:进行多源分析的深度网络研究
  • 实际应用:数据提取与研究的实用案例

核心功能

全面工具集

  • 单页面爬虫:从单个URL中提取内容,支持高级选项
  • 批量处理:高效地并行爬取多个URL
  • 网站映射:发现网站上的所有URL以供探索
  • 网络搜索:搜索网络并从结果中提取内容
  • 全站爬取:执行全面的网站分析,并控制爬取深度
  • 结构化提取:利用AI从页面中提取特定数据点
  • 深度研究:进行多源分析的深度研究
  • LLMs.txt生成:为领域创建标准化的AI交互指南

高级功能

  • 自动限速:内置重试逻辑与退避策略
  • 多种输出格式:支持Markdown、HTML和JSON
  • 内容过滤:高级内容选择与排除选项
  • 移动/桌面渲染:选择不同的渲染模式
  • 认证支持:处理需要登录凭据的站点
  • JavaScript渲染:全面支持动态内容

先决条件

必需依赖

  1. Node.js:Firecrawl MCP服务器所需

    # Install Node.js if not already installed # Visit https://nodejs.org/ for installation instructions
  2. Firecrawl API密钥:从Firecrawl.dev获取您的API密钥

    # Set your API key as an environment variable export FIRECRAWL_API_KEY=your_api_key_here
  3. Google ADK依赖:确保您已安装所需的软件包

    pip install -r ../requirements.txt

️ 设置说明

1. 环境配置

# Set your Firecrawl API key export FIRECRAWL_API_KEY=fc-your_api_key_here # Optional: Configure retry settings export FIRECRAWL_RETRY_MAX_ATTEMPTS=5 export FIRECRAWL_RETRY_INITIAL_DELAY=2000

2. 安装依赖

# From the tutorials root directory pip install -r requirements.txt

3. 运行代理

# From the tutorials root directory adk web

然后从下拉菜单中选择firecrawl_mcp_agent

使用示例

基本网络爬虫

User: "Scrape the homepage of https://example.com" Agent: Uses firecrawl_scrape to extract clean content in Markdown format

批量URL处理

User: "Extract content from these three articles: [url1, url2, url3]" Agent: Uses firecrawl_batch_scrape for efficient parallel processing

网站发现

User: "Find all blog post URLs on https://blog.example.com" Agent: Uses firecrawl_map to discover and list all available URLs

网络搜索与提取

User: "Search for research papers on AI Agents in the last 4 weeks and extract key information" Agent: Uses firecrawl_search to find relevant papers and extract summaries

结构化数据提取

User: "Extract product details (name, price, description) from this e-commerce page" Agent: Uses firecrawl_extract with custom schema for structured data

深度研究

User: "Perform comprehensive research on sustainable energy technologies" Agent: Uses firecrawl_deep_research for multi-source analysis and synthesis

网站爬取

User: "Crawl the documentation section of https://docs.example.com" Agent: Uses firecrawl_crawl with appropriate depth and filtering

可用工具

核心爬虫工具

工具 目的 最佳适用场景
firecrawl_scrape Single page extraction Known URLs, specific pages
firecrawl_batch_scrape Multiple URL processing Lists of URLs, parallel extraction
firecrawl_map URL discovery Exploring site structure

Advanced Tools

Tool Purpose Best For
firecrawl_search Web search + extraction Finding relevant content
firecrawl_crawl Full site crawling Comprehensive site analysis
firecrawl_extract Structured data extraction Specific data points
firecrawl_deep_research Multi-source research Complex research tasks

Utility Tools

Tool Purpose Best For
firecrawl_generate_llmstxt LLMs.txt generation AI interaction guidelines
firecrawl_check_crawl_status Monitor crawl progress Long-running operations
firecrawl_check_batch_status Monitor batch progress Batch operation tracking

Best Practices

Tool Selection Guide

  • Single URL: Use firecrawl_scrape
  • Multiple known URLs: Use firecrawl_batch_scrape
  • Discover URLs: Use firecrawl_map first
  • Search the web: Use firecrawl_search
  • Structured data: Use firecrawl_extract
  • Deep research: Use firecrawl_deep_research
  • Full site analysis: Use firecrawl_crawl (with limits)

Performance Optimization

  • Use batch operations for multiple URLs instead of individual scrapes
  • Set appropriate limits for crawl operations to avoid timeouts
  • Monitor long-running operations with status check tools
  • Respect rate limits and be considerate of target websites

Content Quality

  • Use onlyMainContent: true 提取干净内容
  • 利用内容过滤选项获得更佳效果
  • 选择合适的输出格式(Markdown用于文本,JSON用于数据)
  • 对于特定数据需求,使用结构化提取

⚙️ 配置选项

爬虫参数

# Example configuration for scrape operations { "formats": ["markdown"], # Output format "onlyMainContent": True, # Extract main content only "waitFor": 1000, # Wait time for page load "timeout": 30000, # Request timeout "mobile": False, # Use mobile rendering "includeTags": ["article", "main"], # Include specific HTML tags "excludeTags": ["nav", "footer"] # Exclude specific HTML tags }

批量处理

# Example batch configuration { "maxUrls": 50, # Maximum URLs to process "parallelLimit": 5, # Parallel processing limit "options": { "formats": ["markdown"], "onlyMainContent": True } }

爬虫参数

# Example crawl configuration { "maxDepth": 2, # Crawl depth limit "limit": 100, # Maximum pages to crawl "allowExternalLinks": False, # Stay within domain "deduplicateSimilarURLs": True # Remove duplicate content }

重要提示

限速机制

  • Firecrawl内置自动限速与重试逻辑
  • 批量操作会排队,可能需要一些时间完成
  • 对于长时间运行的任务,请监控操作状态

资源管理

  • 爬虫操作可能占用大量资源
  • 设置适当的限制以避免超时或过度消耗令牌
  • 对于大型操作,使用批量状态检查

API使用

  • 需要有效的Firecrawl API密钥才能进行云端操作
  • 对于高流量使用,可考虑自托管部署
  • 通过Firecrawl仪表板监控额度使用情况

故障排除

常见问题

连接错误

# Check Node.js installation node --version # Test Firecrawl MCP server npx -y firecrawl-mcp

API密钥问题

# Verify API key is set echo $FIRECRAWL_API_KEY # Test API key validity curl -H "Authorization: Bearer $FIRECRAWL_API_KEY" https://api.firecrawl.dev/v1/scrape

工具未找到

  • 确保ADK MCP服务器配置正确
  • 检查Node.js是否已安装且可访问
  • 确认Firecrawl MCP包可以成功安装

调试命令

# Test MCP server connection npx @modelcontextprotocol/inspector # Run agent with debug output adk web --debug

更多资源

实际应用

数据收集与研究

  • 市场调研与竞争对手分析
  • 学术研究与论文收集
  • 新闻监测与趋势分析
  • 产品目录提取
  • 社交媒体内容分析

内容管理

  • 网站迁移与内容审计
  • SEO分析与优化
  • 内容质量评估
  • 文档提取
  • 知识库创建

商业智能

  • 潜在客户开发与联系人提取
  • 价格监测与比较
  • 评论与情感分析
  • 行业趋势追踪
  • 法规合规监测

免责声明
本文档采用基于机器的 AI 翻译服务进行翻译。尽管我们力求准确,但请注意,自动翻译可能存在错误或不准确之处。应以原文语言版本的原始文档作为权威依据。如需获取关键信息,建议使用专业的人工翻译。对于因使用本翻译而产生的任何误解或误读,我们概不负责。


作者与出处
原作者: Shubhamsaboo
来源:Shubhamsaboo
许可证:Apache-2.0
整理: 灏天文库整理
由灏天文库结构化整理,提供目录导航、全文检索与在线阅读,便于系统化学习
发布者: 作者: Shubhamsaboo 转发
评论区 (0)
U