ScrapeGraphAI/Scrapegraph-ai
GitHub: ScrapeGraphAI/Scrapegraph-ai
ScrapeGraphAI 是一个基于 LLM 和有向图逻辑的 Python 网页抓取库,用户通过自然语言 prompt 即可从网站和本地文档中自动提取结构化数据。
Stars: 28790 | Forks: 2807
## 🚀 **想要一种更快、更简单的大规模抓取方式(仅需 5 行代码)?** 请访问我们在 [**ScrapeGraphAI.com**](https://scrapegraphai.com/?utm_source=github&utm_medium=readme&utm_campaign=oss_cta&ut#m_content=top_banner) 的增强版本!🚀
# 🕷️ ScrapeGraphAI:You Only Scrape Once
[English](README.md) | [中文](docs/chinese.md) | [日本語](docs/japanese.md)
| [한국어](docs/korean.md)
| [Русский](docs/russian.md) | [Türkçe](docs/turkish.md)
| [Deutsch](docs/german.md)
| [Español](docs/spanish.md)
| [français](docs/french.md)
| [Português](docs/portuguese.md)
| [Italiano](docs/italian.md)
[](https://pepy.tech/projects/scrapegraphai)
[](https://opensource.org/licenses/MIT)
[](https://discord.gg/gkxQDAjfeX)
[ScrapeGraphAI](https://scrapegraphai.com) 是一个使用 LLM 和直接图逻辑为网站和本地文档(XML、HTML、JSON、Markdown 等)创建抓取 pipeline 的 *web scraping* Python 库。 只需说出你想提取的信息,该库就会为你完成! ## 🚀 集成 ScrapeGraphAI 提供了与流行框架和工具的无缝集成,以增强你的抓取能力。无论你是使用 Python 还是 Node.js 进行构建,使用 LLM 框架,还是使用无代码平台,我们全面的集成选项都能满足你的需求。
你可以在以下[链接](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 server**:[链接](https://smithery.ai/server/@ScrapeGraphAI/scrapegraph-mcp) ## 🚀 快速安装 Scrapegraph-ai 的参考页面可在 PyPI 的官方页面上找到:[pypi](https://pypi.org/project/scrapegraphai/)。 ``` pip install scrapegraphai # IMPORTANT (for fetching websites content) playwright install ``` **注意**:建议在虚拟环境中安装该库,以避免与其他库发生冲突 🐱 ## 💻 用法 有多种标准的抓取 pipeline 可用于从网站(或本地文件)提取信息。 最常见的是 `SmartScraperGraph`,它根据用户 prompt 和源 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)) ``` 输出将是一个类似以下的字典: ``` { "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" } } ``` 还有其他 pipeline 可用于从多个页面提取信息、生成 Python 脚本,甚至生成音频文件。 | Pipeline 名称 | 描述 | |-------------------------|------------------------------------------------------------------------------------------------------------------| | SmartScraperGraph | 单页抓取器,只需要一个用户 prompt 和一个输入源。 | | SearchGraph | 多页抓取器,从搜索引擎的前 n 个搜索结果中提取信息。 | | SpeechGraph | 单页抓取器,从网站提取信息并生成音频文件。 | | ScriptCreatorGraph | 单页抓取器,从网站提取信息并生成 Python 脚本。 | | SmartScraperMultiGraph | 多页抓取器,根据单个 prompt 和源列表从多个页面提取信息。 | | ScriptCreatorMultiGraph | 多页抓取器,生成用于从多个页面和源提取信息的 Python 脚本。 | 这些 graph 每一个都有 multi 版本。它允许并行调用 LLM。 可以通过 API 使用不同的 LLM,例如 **OpenAI**、**Groq**、**Azure**、**Gemini**、**[MiniMax](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)找到。 ## 🆚 开源 vs 托管 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 渲染** | 由你配置 | 托管管理(隐身、`auto`/`fast`/`js` 模式) | | **代理和反机器人** | 由你负责 | 已包含 | | **扩展和维护** | 由你负责 | 完全托管管理 | | **成本模型** | LLM token + 你自己的基础设施 | 按量付费的 credits | | **认证** | 你自己的 LLM 密钥 | `SGAI_API_KEY` | | **功能** | Graph pipeline(SmartScraper、Search、Speech、ScriptCreator 等) | Scrape、Extract、Search、Crawl、Monitor、History | | **设置工作量** | 配置较多 | 极少 — API 密钥 + 一次调用 | | **许可** | MIT | SDK 为 MIT;API 服务为付费 | **选择开源库**,如果你想获得完全控制权、本地/自托管数据、本地 LLM (Ollama) 或进行精细的成本调整 —— 并且你愿意自己管理浏览器、代理和扩展。 **选择托管 API**,如果你想要零基础设施、托管的 JS 渲染和反机器人功能、内置的 **Crawl** 和定时的 **Monitor** 任务,以及最快投入生产的途径 —— 按 credit 计费。 - 开源库: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 ## 🔗 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)的文档。 ## 🎓 引用 如果你出于研究目的使用了我们的库,请使用以下参考文献引用我们: ``` @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 追踪](https://static.scarf.sh/a.png?x-pxid=102d4b8c-cd6a-4b9e-9a16-d6d141b9212d)标签:BeEF, DLL 劫持, Python, URL抓取, 信息提取, 大语言模型, 数据抓取, 无后门, 爬虫, 特征检测, 逆向工具