AI爬虫技术:Firecrawl与ScrapeGraphAI

介绍Firecrawl和ScrapeGraphAI两款AI驱动的网页抓取工具,涵盖安装、配置、核心功能及使用示例。

Firecrawl

GitHub - mendableai/firecrawl: 🔥 Turn entire websites into LLM-ready markdown or structured data. Scrape, crawl and extract with a single API.

https://raw.githubusercontent.com/mendableai/firecrawl/main/img/firecrawl_logo.png

https://camo.githubusercontent.com/a6f4431b80529dbeaa43c3c5fbcf4649f6b4ebbeb82d5a58abeb39ca3eeca8be/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d656e6461626c6561692f66697265637261776c https://camo.githubusercontent.com/9d76afe428b4085c8b7103f2f4e31da110ee154ad7320bace4348d92ac0c2450/68747470733a2f2f7374617469632e706570792e746563682f62616467652f66697265637261776c2d7079 https://camo.githubusercontent.com/036be24bb56e21d894aeb2234bbe65781361dfbbf374f04917d75c676fff339b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6d656e6461626c6561692f66697265637261776c2e737667 https://camo.githubusercontent.com/3576b8cb0e77344c001cc8456d28c830691cb96480d4b65be90f8a4c99dead56/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56697369742d66697265637261776c2e6465762d6f72616e6765

https://camo.githubusercontent.com/610127222e603752676f0275682f12398f8e434706861d577c1f6688d999191c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f466f6c6c6f772532306f6e253230582d3030303030303f7374796c653d666f722d7468652d6261646765266c6f676f3d78266c6f676f436f6c6f723d7768697465 https://camo.githubusercontent.com/8741d51bb8e1c8ae576ac05e875f826bcf80e8711dcf9225935bb78d5bb03802/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f466f6c6c6f772532306f6e2532304c696e6b6564496e2d3030373742353f7374796c653d666f722d7468652d6261646765266c6f676f3d6c696e6b6564696e266c6f676f436f6c6f723d7768697465 https://camo.githubusercontent.com/886138c89a84dc2ad74d06900f364d736ccf753b2732d59fbd4106f6310f3616/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4a6f696e2532306f7572253230446973636f72642d3538363546323f7374796c653d666f722d7468652d6261646765266c6f676f3d646973636f7264266c6f676f436f6c6f723d7768697465

Empower your AI apps with clean data from any website. Featuring advanced scraping, crawling, and data extraction capabilities. 赋予您的 AI 应用来自任何网站的干净数据。具备先进的抓取、爬取和数据提取功能。

This repository is in development, and we’re still integrating custom modules into the mono repo. It’s not fully ready for self-hosted deployment yet, but you can run it locally. 此存储库处于开发中,我们仍在将自定义模块集成到单一代码库中。它尚未完全准备好进行自托管部署,但您可以在本地运行它。

What is Firecrawl?

Firecrawl is an API service that takes a URL, crawls it, and converts it into clean markdown or structured data. We crawl all accessible subpages and give you clean data for each. No sitemap required. Check out our documentation. Firecrawl 是一个 API 服务,它接受一个 URL,对其进行抓取,并将其转换为干净的 Markdown 或结构化数据。我们抓取所有可访问的子页面,并为每个页面提供干净的数据。无需地图。查看我们的文档

二、ScrapeGraphAI

概述

ScrapeGraphAI 是一款基于大语言模型(LLM)的智能网页抓取Python库,通过直接图逻辑构建自动化数据抽取管道。支持处理:

  • 🌐 网页数据(HTML/XML) + 📁 本地文档(JSON/Markdown等) + 🔍 搜索引擎结果聚合 + 🔊 语音文件生成

核心优势:无需编写复杂解析规则,通过自然语言指令即可完成结构化数据抽取。


安装


快速开始

单页面智能抓取(SmartScraper)


核心功能

1. SmartScraperGraph

  • 单页面精准抓取 + 输入:URL/文件路径 + 自然语言指令 + 输出:结构化JSON数据

2. SearchGraph

  • 多页面聚合抓取 + 特点:
  • 自动抓取搜索引擎前N条结果
  • 支持Google/Bing等主流引擎
  • 跨站数据聚合分析

3. SpeechGraph

  • 语音数据生成 + 支持特性:
  • 网页内容转语音(MP3/WAV)
  • 多语言支持
  • 语音风格定制

配置说明

LLM 配置模板


示例输出


支持模型

服务类型 支持模型
OpenAI gpt-4o-mini, gpt-3.5-turbo
Ollama llama3, mistral, phi3
Anthropic claude-3-opus
Groq mixtral-8x7b-32768

注意事项

  • 建议在虚拟环境中安装
  • 处理复杂页面时启用"headless": True
  • 商业用途需遵守目标网站的robots.txt协议
  • 大文档处理时注意token限制
  • 语音生成功能需安装额外依赖:pip install pydub
bash2 行
# 使用虚拟环境推荐
pip install scrapegraph-ai
python22 行
from scrapegraphai.graphs import SmartScraperGraph

# 配置LLM(以Ollama/Llama3为例)
graph_config = {
    "llm": {
        "model": "ollama/llama3",
        "model_tokens": 8192
    },
    "verbose": True,
    "headless": False
}

# 创建抓取管道
smart_scraper = SmartScraperGraph(
    prompt="提取公司简介、创始人信息及社交媒体链接",
    source="https://scrapegraphai.com/",
    config=graph_config
)

# 执行抓取
result = smart_scraper.run()
print(result)
python17 行
# OpenAI 配置
{
    "llm": {
        "api_key": "YOUR_KEY",  # 必填
        "model": "openai/gpt-4o-mini",
        "temperature": 0.1  # 控制输出稳定性
    },
    "max_retries": 3  # 错误重试次数
}

# 本地模型配置(Ollama)
{
    "llm": {
        "model": "ollama/mistral",
        "base_url": "http://localhost:11434"  # Ollama服务地址
    }
}
json14 行
{
    "description": "ScrapeGraphAI 提供AI驱动的数据提取API,可将网站转化为结构化数据",
    "founders": [
        {
            "name": "Marco Vinciguerra",
            "role": "联合创始人兼软件工程师",
            "linkedin": "https://linkedin.com/in/marco-vinciguerra"
        }
    ],
    "social_media": {
        "github": "https://github.com/ScrapeGraphAI",
        "twitter": "https://x.com/scrapegraphai"
    }
}