|
| 1 | +# 🕷️ ScrapeGraphAI: 只需抓取一次 |
| 2 | +[](https://pepy.tech/project/scrapegraphai) |
| 3 | +[](https://github.com/pylint-dev/pylint) |
| 4 | +[](https://github.com/VinciGit00/Scrapegraph-ai/actions/workflows/pylint.yml) |
| 5 | +[](https://github.com/VinciGit00/Scrapegraph-ai/actions/workflows/codeql.yml) |
| 6 | +[](https://opensource.org/licenses/MIT) |
| 7 | +[](https://discord.gg/gkxQDAjfeX) |
| 8 | + |
| 9 | +ScrapeGraphAI 是一个*网络爬虫* Python 库,使用大型语言模型和直接图逻辑为网站和本地文档(XML,HTML,JSON 等)创建爬取管道。 |
| 10 | + |
| 11 | +只需告诉库您想提取哪些信息,它将为您完成! |
| 12 | + |
| 13 | +<p align="center"> |
| 14 | + <img src="https://raw.githubusercontent.com/VinciGit00/Scrapegraph-ai/main/docs/assets/scrapegraphai_logo.png" alt="Scrapegraph-ai Logo" style="width: 50%;"> |
| 15 | +</p> |
| 16 | + |
| 17 | +## 🚀 快速安装 |
| 18 | + |
| 19 | +Scrapegraph-ai 的参考页面可以在 PyPI 的官方网站上找到: [pypi](https://pypi.org/project/scrapegraphai/)。 |
| 20 | + |
| 21 | +```bash |
| 22 | +pip install scrapegraphai |
| 23 | +``` |
| 24 | +注意: 建议在虚拟环境中安装该库,以避免与其他库发生冲突 🐱 |
| 25 | + |
| 26 | +🔍 演示 |
| 27 | + |
| 28 | +官方 Streamlit 演示: |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +在 Google Colab 上直接尝试: |
| 33 | + |
| 34 | +## 📖 文档 |
| 35 | + |
| 36 | +ScrapeGraphAI 的文档可以在这里找到。 |
| 37 | + |
| 38 | +还可以查看 Docusaurus 这里。 |
| 39 | + |
| 40 | +## 💻 用法 |
| 41 | + |
| 42 | +有三种主要的爬取管道可用于从网站(或本地文件)提取信息: |
| 43 | + |
| 44 | +SmartScraperGraph: 单页爬虫,只需用户提示和输入源; |
| 45 | +SearchGraph: 多页爬虫,从搜索引擎的前 n 个搜索结果中提取信息; |
| 46 | +SpeechGraph: 单页爬虫,从网站提取信息并生成音频文件。 |
| 47 | +SmartScraperMultiGraph: 多页爬虫,给定一个提示 |
| 48 | +可以通过 API 使用不同的 LLM,如 OpenAI,Groq,Azure 和 Gemini,或者使用 Ollama 的本地模型。 |
| 49 | + |
| 50 | +案例 1: 使用本地模型的 SmartScraper |
| 51 | +请确保已安装 Ollama 并使用 ollama pull 命令下载模型。 |
| 52 | + |
| 53 | +``` python |
| 54 | +from scrapegraphai.graphs import SmartScraperGraph |
| 55 | + |
| 56 | +graph_config = { |
| 57 | + "llm": { |
| 58 | + "model": "ollama/mistral", |
| 59 | + "temperature": 0, |
| 60 | + "format": "json", # Ollama 需要显式指定格式 |
| 61 | + "base_url": "http://localhost:11434", # 设置 Ollama URL |
| 62 | + }, |
| 63 | + "embeddings": { |
| 64 | + "model": "ollama/nomic-embed-text", |
| 65 | + "base_url": "http://localhost:11434", # 设置 Ollama URL |
| 66 | + }, |
| 67 | + "verbose": True, |
| 68 | +} |
| 69 | + |
| 70 | +smart_scraper_graph = SmartScraperGraph( |
| 71 | + prompt="列出所有项目及其描述", |
| 72 | + # 也接受已下载的 HTML 代码的字符串 |
| 73 | + source="https://perinim.github.io/projects", |
| 74 | + config=graph_config |
| 75 | +) |
| 76 | + |
| 77 | +result = smart_scraper_graph.run() |
| 78 | +print(result) |
| 79 | +``` |
| 80 | + |
| 81 | +输出将是一个包含项目及其描述的列表,如下所示: |
| 82 | + |
| 83 | +python |
| 84 | +Copia codice |
| 85 | +{'projects': [{'title': 'Rotary Pendulum RL', 'description': '开源项目,旨在使用 RL 算法控制现实中的旋转摆'}, {'title': 'DQN Implementation from scratch', 'description': '开发了一个深度 Q 网络算法来训练简单和双摆'}, ...]} |
| 86 | +案例 2: 使用混合模型的 SearchGraph |
| 87 | +我们使用 Groq 作为 LLM,使用 Ollama 作为嵌入模型。 |
| 88 | + |
| 89 | +```python |
| 90 | +from scrapegraphai.graphs import SearchGraph |
| 91 | + |
| 92 | +# 定义图的配置 |
| 93 | +graph_config = { |
| 94 | + "llm": { |
| 95 | + "model": "groq/gemma-7b-it", |
| 96 | + "api_key": "GROQ_API_KEY", |
| 97 | + "temperature": 0 |
| 98 | + }, |
| 99 | + "embeddings": { |
| 100 | + "model": "ollama/nomic-embed-text", |
| 101 | + "base_url": "http://localhost:11434", # 任意设置 Ollama URL |
| 102 | + }, |
| 103 | + "max_results": 5, |
| 104 | +} |
| 105 | + |
| 106 | +# 创建 SearchGraph 实例 |
| 107 | +search_graph = SearchGraph( |
| 108 | + prompt="列出所有来自基奥贾的传统食谱", |
| 109 | + config=graph_config |
| 110 | +) |
| 111 | + |
| 112 | +# 运行图 |
| 113 | +result = search_graph.run() |
| 114 | +print(result) |
| 115 | +``` |
| 116 | + |
| 117 | +输出将是一个食谱列表,如下所示: |
| 118 | + |
| 119 | +```python |
| 120 | +{'recipes': [{'name': 'Sarde in Saòre'}, {'name': 'Bigoli in salsa'}, {'name': 'Seppie in umido'}, {'name': 'Moleche frite'}, {'name': 'Risotto alla pescatora'}, {'name': 'Broeto'}, {'name': 'Bibarasse in Cassopipa'}, {'name': 'Risi e bisi'}, {'name': 'Smegiassa Ciosota'}]} |
| 121 | +案例 3: 使用 OpenAI 的 SpeechGraph |
| 122 | +您只需传递 OpenAI API 密钥和模型名称。 |
| 123 | +``` |
| 124 | +```python |
| 125 | +from scrapegraphai.graphs import SpeechGraph |
| 126 | + |
| 127 | +graph_config = { |
| 128 | + "llm": { |
| 129 | + "api_key": "OPENAI_API_KEY", |
| 130 | + "model": "gpt-3.5-turbo", |
| 131 | + }, |
| 132 | + "tts_model": { |
| 133 | + "api_key": "OPENAI_API_KEY", |
| 134 | + "model": "tts-1", |
| 135 | + "voice": "alloy" |
| 136 | + }, |
| 137 | + "output_path": "audio_summary.mp3", |
| 138 | +} |
| 139 | + |
| 140 | +# ************************************************ |
| 141 | +# 创建 SpeechGraph 实例并运行 |
| 142 | +# ************************************************ |
| 143 | + |
| 144 | +speech_graph = SpeechGraph( |
| 145 | + prompt="详细总结这些项目并生成音频。", |
| 146 | + source="https://perinim.github.io/projects/", |
| 147 | + config=graph_config, |
| 148 | +) |
| 149 | + |
| 150 | +result = speech_graph.run() |
| 151 | +print(result) |
| 152 | +``` |
| 153 | +输出将是一个包含页面上项目摘要的音频文件。 |
| 154 | + |
| 155 | +## 🤝 贡献 |
| 156 | + |
| 157 | +欢迎贡献并加入我们的 Discord 服务器与我们讨论改进和提出建议! |
| 158 | + |
| 159 | +请参阅贡献指南。 |
| 160 | + |
| 161 | + |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +📈 路线图 |
| 166 | + |
| 167 | +查看项目路线图这里! 🚀 |
| 168 | + |
| 169 | +想要以更互动的方式可视化路线图?请查看 markmap 通过将 markdown 内容复制粘贴到编辑器中进行可视化! |
| 170 | + |
| 171 | +## ❤️ 贡献者 |
| 172 | + |
| 173 | + |
| 174 | +赞助商 |
| 175 | + |
| 176 | +<div style="text-align: center;"> |
| 177 | + <a href="https://serpapi.com?utm_source=scrapegraphai"> |
| 178 | + <img src="https://raw.githubusercontent.com/VinciGit00/Scrapegraph-ai/main/docs/assets/serp_api_logo.png" alt="SerpAPI" style="width: 10%;"> |
| 179 | + </a> |
| 180 | + <a href="https://dashboard.statproxies.com/?refferal=scrapegraph"> |
| 181 | + <img src="https://raw.githubusercontent.com/VinciGit00/Scrapegraph-ai/main/docs/assets/transparent_stat.png" alt="Stats" style="width: 15%;"> |
| 182 | + </a> |
| 183 | +</div> |
| 184 | + |
| 185 | +## 🎓 引用 |
| 186 | + |
| 187 | +如果您将我们的库用于研究目的,请引用以下参考文献: |
| 188 | +```text |
| 189 | + @misc{scrapegraph-ai, |
| 190 | + author = {Marco Perini, Lorenzo Padoan, Marco Vinciguerra}, |
| 191 | + title = {Scrapegraph-ai}, |
| 192 | + year = {2024}, |
| 193 | + url = {https://github.com/VinciGit00/Scrapegraph-ai}, |
| 194 | + note = {一个利用大型语言模型进行爬取的 Python 库} |
| 195 | + } |
| 196 | +``` |
| 197 | +## 作者 |
| 198 | + |
| 199 | +<p align="center"> |
| 200 | + <img src="https://raw.githubusercontent.com/VinciGit00/Scrapegraph-ai/main/docs/assets/logo_authors.png" alt="Authors_logos"> |
| 201 | +</p> |
| 202 | +## 联系方式 |
| 203 | + |
| 204 | +Marco Vinciguerra |
| 205 | +Marco Perini |
| 206 | +Lorenzo Padoan |
| 207 | +## 📜 许可证 |
| 208 | + |
| 209 | +ScrapeGraphAI 采用 MIT 许可证。更多信息请查看 LICENSE 文件。 |
| 210 | + |
| 211 | +鸣谢 |
| 212 | + |
| 213 | +我们要感谢所有项目贡献者和开源社区的支持。 |
| 214 | +ScrapeGraphAI 仅用于数据探索和研究目的。我们不对任何滥用该库的行为负责。 |
0 commit comments