## 🚀 **想要一种更快、更简单的大规模抓取方式(只需 5 行代码)?** 请查看我们在 [**ScrapeGraphAI.com**](https://scrapegraphai.com/?utm_source=github&utm_medium=readme&utm_campaign=oss_cta&ut#m_content=top_banner) 上的增强版本!🚀
---
# 🕷️ ScrapeGraphAI:你只需抓取一次
<p align="center">
<a href="https://scrapegraphai.com">
<img src="https://assets.kitploit.com/production/public/readmes/41478/e11a555115b80e07241afdb0aec04ee9fae66f983d969d27fbd8a64a21f090de.png" alt="ScrapeGraphAI" style="width: 100%;">
</a>
</p>
[English](https://github.com/scrapegraphai/scrapegraph-ai/blob/main/README.md) | [中文](https://github.com/scrapegraphai/scrapegraph-ai/blob/main/docs/chinese.md) | [日本語](https://github.com/scrapegraphai/scrapegraph-ai/blob/main/docs/japanese.md)
| [한국어](https://github.com/scrapegraphai/scrapegraph-ai/blob/main/docs/korean.md)
| [Русский](https://github.com/scrapegraphai/scrapegraph-ai/blob/main/docs/russian.md) | [Türkçe](https://github.com/scrapegraphai/scrapegraph-ai/blob/main/docs/turkish.md)
| [Deutsch](https://github.com/scrapegraphai/scrapegraph-ai/blob/main/docs/german.md)
| [Español](https://github.com/scrapegraphai/scrapegraph-ai/blob/main/docs/spanish.md)
| [français](https://github.com/scrapegraphai/scrapegraph-ai/blob/main/docs/french.md)
| [Português](https://github.com/scrapegraphai/scrapegraph-ai/blob/main/docs/portuguese.md)
| [Italiano](https://github.com/scrapegraphai/scrapegraph-ai/blob/main/docs/italian.md)
[](https://pepy.tech/projects/scrapegraphai)
[](https://opensource.org/licenses/MIT)
[](https://discord.gg/gkxQDAjfeX)
<p align="center">
<a href="https://trendshift.io/repositories/15078" target="_blank"><img src="https://trendshift.io/api/badge/repositories/15078" alt="ScrapeGraphAI%2FScrapegraph-ai | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
<p align="center">
[ScrapeGraphAI](https://scrapegraphai.com) 是一个 *网页抓取* Python 库,它利用 LLM 和直接图逻辑为网站和本地文档(XML、HTML、JSON、Markdown 等)创建抓取管道。
只需说出你想提取哪些信息,这个库就会为你完成!
## 🚀 集成
ScrapeGraphAI 提供与主流框架和工具的无缝集成,以增强你的抓取能力。无论你是在使用 Python 或 Node.js 开发、使用 LLM 框架,还是在使用无代码平台,我们全面的集成选项都能满足你的需求。
<p align="center">
<a href="https://scrapegraphai.com">
<img src="https://assets.kitploit.com/production/public/readmes/41478/0e788431fde2dc01cf2aa4b53d87b9befe3c728b719a5a45dec11ffb4d7c77a5.png" alt="需要大规模网页数据提取?试试 ScrapeGraphAI 云服务" style="width: 100%;">
</a>
</p>
你可以在以下[链接](https://scrapegraphai.com)找到更多信息
**集成**:
- **API**:[文档](https://docs.scrapegraphai.com/introduction)
- **SDK**:[Python](https://docs.scrapegraphai.com/sdks/python)、[Node](https://docs.scrapegraphai.com/sdks/javascript)
- **LLM 框架**:[Langchain](https://docs.scrapegraphai.com/integrations/langchain)、[Llama Index](https://docs.scrapegraphai.com/integrations/llamaindex)、[Crew.ai](https://docs.scrapegraphai.com/integrations/crewai)、[Agno](https://docs.scrapegraphai.com/integrations/agno)、[CamelAI](https://github.com/camel-ai/camel)
- **低代码框架**:[Pipedream](https://pipedream.com/apps/scrapegraphai)、[Bubble](https://bubble.io/plugin/scrapegraphai-1745408893195x213542371433906180)、[Zapier](https://zapier.com/apps/scrapegraphai/integrations)、[n8n](http://localhost:5001/dashboard)、[Dify](https://dify.ai)、[Toolhouse](https://app.toolhouse.ai/mcp-servers/scrapegraph_smartscraper)
- **MCP 服务器**:[链接](https://smithery.ai/server/@ScrapeGraphAI/scrapegraph-mcp)
## 🚀 快速安装
Scrapegraph-ai 的参考页面可在 PyPI 官方页面查看:[pypi](https://pypi.org/project/scrapegraphai/)。
```bash
pip install scrapegraphai
# IMPORTANT (for fetching websites content)
playwright install
```
**注意**:建议在虚拟环境中安装该库,以避免与其他库发生冲突 🐱
## 💻 使用
有多种标准抓取管道可用于从网站(或本地文件)中提取信息。
最常用的是 `SmartScraperGraph`,它根据用户提示和源 URL 从单个页面提取信息。
```python
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 配置!
> ```python
>graph_config = {
> "llm": {
> "api_key": "YOUR_OPENAI_API_KEY",
> "model": "openai/gpt-4o-mini",
> },
> "verbose": True,
> "headless": False,
>}
>```
输出将是如下所示的字典:
```python
{
"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 脚本,甚至生成音频文件。
| 管道名称 | 描述 |
|---|---|
| SmartScraperGraph | 单页抓取器,只需用户提示和输入源即可。 |
| SearchGraph | 多页抓取器,从搜索引擎的前 n 个搜索结果中提取信息。 |
| SpeechGraph | 单页抓取器,从网站提取信息并生成音频文件。 |
| ScriptCreatorGraph | 单页抓取器,从网站提取信息并生成 Python 脚本。 |
| SmartScraperMultiGraph | 多页抓取器,根据单一提示和源列表从多个页面提取信息。 |
| ScriptCreatorMultiGraph | 多页抓取器,生成 Python 脚本,用于从多个页面和源提取信息。 |
这些图都有对应的多页面(multi)版本,可以并行调用 LLM。
可以通过 API 使用不同的 LLM,例如 **OpenAI**、**Groq**、**Azure**、**Gemini**、**[MiniMax](https://github.com/scrapegraphai/scrapegraph-ai/blob/main/docs/minimax.md)** 等,也可以通过 **Ollama** 使用本地模型。
如果你想使用本地模型,请记得安装 [Ollama](https://ollama.com/),并使用 **ollama pull** 命令下载模型。
## 📖 文档
[](https://colab.research.google.com/drive/1sEZBonBMGP44CtO6GQTwAlL0BGJXjtfd?usp=sharing)
ScrapeGraphAI 的文档可以在[这里](https://docs.scrapegraphai.com/introduction)找到。
## 🆚 开源版与托管 API
ScrapeGraphAI 有两种形态:**这个开源库**(由你自己运行)和**托管云 API**(通过 [Python](https://github.com/ScrapeGraphAI/scrapegraph-py) 和 [JS/TS](https://github.com/ScrapeGraphAI/scrapegraph-js) SDK 使用)。下表说明了二者的区别,以帮助你选择合适的一款。
| | 开源版(`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 服务为付费 |
如果你想完全掌控、数据本地化/自托管、使用本地 LLM(Ollama)或进行细粒度的成本调优——并且愿意自行管理浏览器、代理和扩展,请选择**开源库**。
如果你想要零基础设施、托管的 JS 渲染与反爬虫、内置的 **Crawl** 和定时 **Monitor** 任务,以及最快上线的路径——按积分计费,请选择**托管 API**。
- 开源库:https://github.com/ScrapeGraphAI/Scrapegraph-ai
- Python SDK:https://github.com/ScrapeGraphAI/scrapegraph-py
- JS/TS SDK:https://github.com/ScrapeGraphAI/scrapegraph-js
- API 文档:https://docs.scrapegraphai.com/introduction
## 🤝 贡献
欢迎贡献代码,并加入我们的 Discord 服务器,与我们讨论改进并给出建议!
请参阅[贡献指南](https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/main/CONTRIBUTING.md)。
[](https://discord.gg/uJN7TYcpNa)
[](https://www.linkedin.com/company/scrapegraphai/)
[](https://twitter.com/scrapegraphai)
## 🔗 ScrapeGraph API 与 SDK
如果你正在寻找将 ScrapeGraph 集成到系统中的快速解决方案,请[在此处](https://scrapegraphai.com)查看我们强大的 API!
[](https://scrapegraphai.com)
我们提供 Python 和 Node.js 两种 SDK,方便你集成到项目中。请看下面的内容:
| SDK | 语言 | GitHub 链接 |
|---|---|---|
| Python SDK | Python | [scrapegraph-py](https://docs.scrapegraphai.com/sdks/python) |
| Node.js SDK | Node.js | [scrapegraph-js](https://docs.scrapegraphai.com/sdks/javascript) |
官方 API 文档可以在[这里](https://docs.scrapegraphai.com/introduction)找到。
## 📈 遥测
我们会收集匿名使用指标,以提升软件包的质量和用户体验。这些数据帮助我们确定改进的优先级并确保兼容性。如果你希望退出,请将环境变量 SCRAPEGRAPHAI_TELEMETRY_ENABLED 设置为 false。更多信息请参阅[此处](https://docs.scrapegraphai.com/introduction)的文档。
## ❤️ 贡献者
[](https://github.com/ScrapeGraphAI/Scrapegraph-ai/graphs/contributors)
## 🎓 引用
如果你已将该库用于研究目的,请使用以下参考文献引用我们:
```text
@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}
}
```
## 作者
| | 联系方式 |
|--------------------|----------------------|
| Marco Vinciguerra | [](https://www.linkedin.com/in/marco-vinciguerra-7ba365242/) |
| Lorenzo Padoan | [](https://www.linkedin.com/in/lorenzo-padoan-4521a2154/) |
## 📜 许可证
ScrapeGraphAI 采用 MIT 许可证。更多信息请参阅 [LICENSE](https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/main/LICENSE) 文件。
## 致谢
- 我们要感谢项目的所有贡献者以及开源社区的支持。
- ScrapeGraphAI 仅供数据探索和研究目的使用。我们不对该库的任何滥用行为负责。
由 [ScrapeGraph AI](https://scrapegraphai.com) 用 ❤️ 制作
[Scarf tracking](https://static.scarf.sh/a.png?x-pxid=102d4b8c-cd6a-4b9e-9a16-d6d141b9212d)