English | 中文 | 日本語 | 한국어 | Русский | Türkçe | Deutsch | Español | français | Português | Italiano
ScrapeGraphAI 是一个 网页抓取 Python 库,它利用 LLM 和直接图逻辑为网站和本地文档(XML、HTML、JSON、Markdown 等)创建抓取管道。
只需说出你想提取哪些信息,这个库就会为你完成!
ScrapeGraphAI 提供与主流框架和工具的无缝集成,以增强你的抓取能力。无论你是在使用 Python 或 Node.js 开发、使用 LLM 框架,还是在使用无代码平台,我们全面的集成选项都能满足你的需求。
你可以在以下链接找到更多信息
集成:
Scrapegraph-ai 的参考页面可在 PyPI 官方页面查看:pypi。
pip install scrapegraphai
# IMPORTANT (for fetching websites content)
playwright install
注意:建议在虚拟环境中安装该库,以避免与其他库发生冲突 🐱
有多种标准抓取管道可用于从网站(或本地文件)中提取信息。
最常用的是 SmartScraperGraph,它根据用户提示和源 URL 从单个页面提取信息。
from scrapegraphai.graphs import SmartScraperGraph
# Define the configuration for the scraping pipeline
graph_config = {
"llm": {
"model": "ollama/llama3.2",
"model_tokens": 8192,
"format": "json",
},
"verbose": True,
"headless": False,
}
# Create the SmartScraperGraph instance
smart_scraper_graph = SmartScraperGraph(
prompt="Extract useful information from the webpage, including a description of what the company does, founders and social media links",
source="https://scrapegraphai.com/",
config=graph_config
)
# Run the pipeline
result = smart_scraper_graph.run()
import json
print(json.dumps(result, indent=4))
[!NOTE] 对于 OpenAI 和其他模型,你只需更改 llm 配置!
graph_config = { "llm": { "api_key": "YOUR_OPENAI_API_KEY", "model": "openai/gpt-4o-mini", }, "verbose": True, "headless": False, }
输出将是如下所示的字典:
{
"description": "ScrapeGraphAI transforms websites into clean, organized data for AI agents and data analytics. It offers an AI-powered API for effortless and cost-effective data extraction.",
"founders": [
{
"name": "",
"role": "Founder & Technical Lead",
"linkedin": "https://www.linkedin.com/in/perinim/"
},
{
"name": "Marco Vinciguerra",
"role": "Founder & Software Engineer",
"linkedin": "https://www.linkedin.com/in/marco-vinciguerra-7ba365242/"
},
{
"name": "Lorenzo Padoan",
"role": "Founder & Product Engineer",
"linkedin": "https://www.linkedin.com/in/lorenzo-padoan-4521a2154/"
}
],
"social_media_links": {
"linkedin": "https://www.linkedin.com/company/101881123",
"twitter": "https://x.com/scrapegraphai",
"github": "https://github.com/ScrapeGraphAI/Scrapegraph-ai"
}
}
还有其他管道可用于从多个页面提取信息、生成 Python 脚本,甚至生成音频文件。
这些图都有对应的多页面(multi)版本,可以并行调用 LLM。
可以通过 API 使用不同的 LLM,例如 OpenAI、Groq、Azure、Gemini、MiniMax 等,也可以通过 Ollama 使用本地模型。
如果你想使用本地模型,请记得安装 Ollama,并使用 ollama pull 命令下载模型。
ScrapeGraphAI 的文档可以在这里找到。
ScrapeGraphAI 有两种形态:这个开源库(由你自己运行)和托管云 API(通过 Python 和 JS/TS SDK 使用)。下表说明了二者的区别,以帮助你选择合适的一款。
如果你想完全掌控、数据本地化/自托管、使用本地 LLM(Ollama)或进行细粒度的成本调优——并且愿意自行管理浏览器、代理和扩展,请选择开源库。
如果你想要零基础设施、托管的 JS 渲染与反爬虫、内置的 Crawl 和定时 Monitor 任务,以及最快上线的路径——按积分计费,请选择托管 API。
欢迎贡献代码,并加入我们的 Discord 服务器,与我们讨论改进并给出建议!
请参阅贡献指南。
如果你正在寻找将 ScrapeGraph 集成到系统中的快速解决方案,请在此处查看我们强大的 API!
我们提供 Python 和 Node.js 两种 SDK,方便你集成到项目中。请看下面的内容:
| SDK | 语言 | GitHub 链接 |
|---|---|---|
| Python SDK | Python | scrapegraph-py |
| Node.js SDK | Node.js | scrapegraph-js |
官方 API 文档可以在这里找到。
我们会收集匿名使用指标,以提升软件包的质量和用户体验。这些数据帮助我们确定改进的优先级并确保兼容性。如果你希望退出,请将环境变量 SCRAPEGRAPHAI_TELEMETRY_ENABLED 设置为 false。更多信息请参阅此处的文档。
如果你已将该库用于研究目的,请使用以下参考文献引用我们:
@misc{scrapegraph-ai,
author = {Lorenzo Padoan, Marco Vinciguerra},
title = {Scrapegraph-ai},
year = {2024},
url = {https://github.com/ScrapeGraphAI/Scrapegraph-ai},
note = {A Python library for scraping leveraging large language models}
}
ScrapeGraphAI 采用 MIT 许可证。更多信息请参阅 LICENSE 文件。
由 ScrapeGraph AI 用 ❤️ 制作
| 管道名称 | 描述 |
|---|
| SmartScraperGraph | 单页抓取器,只需用户提示和输入源即可。 |
| SearchGraph | 多页抓取器,从搜索引擎的前 n 个搜索结果中提取信息。 |
| SpeechGraph | 单页抓取器,从网站提取信息并生成音频文件。 |
| ScriptCreatorGraph | 单页抓取器,从网站提取信息并生成 Python 脚本。 |
| SmartScraperMultiGraph | 多页抓取器,根据单一提示和源列表从多个页面提取信息。 |
| ScriptCreatorMultiGraph | 多页抓取器,生成 Python 脚本,用于从多个页面和源提取信息。 |
开源版(scrapegraphai) | 托管 API(scrapegraph-py / scrapegraph-js) |
|---|
| 是什么 | 由你自己运行的 Python 库 | 通过 SDK 调用的托管云服务 |
| 运行位置 | 你自己的基础设施(自托管) | ScrapeGraphAI 云 |
| LLM | 自带(OpenAI、Groq、Gemini、Azure、通过 Ollama 使用本地模型) | 由我们托管 |
| 浏览器 / JS 渲染 | 由你配置(Playwright) | 托管(隐身模式、auto/fast/js 模式) |
| 代理与反爬虫 | 由你负责 | 已包含 |
| 扩展与维护 | 由你负责 | 完全托管 |
| 成本模式 | LLM token + 自有基础设施 | 按量付费积分 |
| 认证 | 你自己的 LLM 密钥 | SGAI_API_KEY |
| 能力 | 图谱管道(SmartScraper、Search、Speech、ScriptCreator…) | Scrape、Extract、Search、Crawl、Monitor、History |
| 设置工作量 | 需要更多配置 | 极少 —— API 密钥 + 一次调用 |
| 许可证 | MIT | SDK 为 MIT;API 服务为付费 |