13 KiB
Note
本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
English · 原始项目 · 上游 README
原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
🚀 想要一种更快、更简单的规模化爬取方式(仅需 5 行代码)? 请访问我们的增强版:ScrapeGraphAI.com! 🚀
🕷️ ScrapeGraphAI:只需爬取一次
English | 中文 | 日本語 | 한국어 | Русский | Türkçe | Deutsch | Español | français | Português | Italiano
ScrapeGraphAI is a web scraping python library that uses LLM and direct graph logic to create scraping pipelines for websites and local documents (XML, HTML, JSON, Markdown, etc.).
只需说明你想提取哪些信息,库会替你完成!
🚀 集成
ScrapeGraphAI 可与主流框架和工具无缝集成,增强你的爬取能力。无论你使用 Python 或 Node.js 开发、使用 LLM 框架,还是与无代码平台协作,我们都提供全面的集成选项..
更多信息请参阅以下链接
集成:
- API: Documentation
- SDKs: Python, Node
- LLM Frameworks: Langchain, Llama Index, Crew.ai, Agno, CamelAI
- Low-code Frameworks: Pipedream, Bubble, Zapier, n8n, Dify, Toolhouse
- MCP server: Link
🚀 快速安装
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 脚本,甚至生成音频文件。
| 流水线名称 | 说明 |
|---|---|
| SmartScraperGraph | 单页爬取器,仅需用户提示和输入源。 |
| SearchGraph | 多页爬取器,从搜索引擎前 n 条搜索结果中提取信息。 |
| SpeechGraph | 单页爬取器,从网站提取信息并生成音频文件。 |
| ScriptCreatorGraph | 单页爬取器,从网站提取信息并生成 Python 脚本。 |
| SmartScraperMultiGraph | 多页爬取器,根据单一提示和源列表从多个页面提取信息。 |
| ScriptCreatorMultiGraph | 多页爬取器,生成用于从多个页面和源提取信息的 Python 脚本。 |
这些图(graph)各自都有 multi 版本,可并行调用 LLM。
可通过 API 使用不同的 LLM,例如 OpenAI、Groq、Azure、Gemini、MiniMax 等,也可通过 Ollama 使用本地模型。
若要使用本地模型,请确保已安装 Ollama,并使用 ollama pull 命令下载模型。
📖 文档
ScrapeGraphAI 文档见此处.
🆚 开源版 vs 托管 API
ScrapeGraphAI 提供两种形态:本开源库由你自行部署运行,以及通过 Python 和 JS/TS SDK 调用的托管云 API。下表说明两者的差异,便于你选择合适方案。
开源版 (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)或精细成本调优——并愿意自行管理浏览器、代理与扩展。
选择托管 API,若你需要零基础设施、托管 JS 渲染与反爬、内置 Crawl 与定时 Monitor 任务,以及最快上线路径——按积分计费。
- 开源库: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 服务器,与我们讨论改进并向我们提出建议!
请参阅贡献指南.
🔗 ScrapeGraph API 与 SDK
若你正在寻找将 ScrapeGraph 集成到系统中的快捷方案,请查看我们强大的 API 这里!
我们提供 Python 和 Node.js 两套 SDK,便于集成到你的项目中。请在下方查看:
| SDK | 语言 | GitHub 链接 |
|---|---|---|
| Python SDK | Python | scrapegraph-py |
| Node.js SDK | Node.js | scrapegraph-js |
官方 API 文档可在此查看 这里.
📈 遥测(Telemetry)
我们收集匿名使用指标以提升软件包质量与用户体验。这些数据帮助我们优先改进并确保兼容性。若要退出,请设置环境变量 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}
}
作者
| 联系方式 | |
|---|---|
| Marco Vinciguerra | |
| Lorenzo Padoan |
📜 许可证
ScrapeGraphAI 采用 MIT 许可证。更多信息请参阅 LICENSE 文件。
致谢
- 感谢所有项目贡献者及开源社区的支持。
- ScrapeGraphAI 仅用于数据探索与研究目的。我们不对库的滥用承担责任。
由 ScrapeGraph AI 用 ❤️ 打造
