你是否曾想过,如果有一个工具,能够理解你的意图并自动执行复杂的网络数据抓取任务,那会怎样?ScrapeGraphAI[1] 就是这样一个工具,它利用最新的人工智能技术,让数据提取变得前所未有地简单。
ScrapeGraphAI 是一个用于网络抓取 Python 库,它使用大语言模型(LLM)和直接图为网站、文档和 XML 文件创建抓取管道。只需说出您想要提取哪些信息,它就会为您完成!
工具特点
-
简单易用:只需输入 API 密钥,您就可以在几秒钟内抓取数千个网页!
-
开发便捷:你只需要实现几行代码,工作就完成了。
-
专注业务:有了这个库,您可以节省数小时的时间,因为您只需要设置项目,人工智能就会为您完成一切。
快速开始
在线示例
1.官方 Streamlit
https://scrapegraph-ai-demo.streamlit.app/
2.Google Colab
https://colab.research.google.com/drive/1sEZBonBMGP44CtO6GQTwAlL0BGJXjtfd
本地安装
使用 pip 安装 scrapegraphai:
pip install scrapegraphai
此外,您还需要安装 Playwright[2] 抓取客户端渲染(由 JavaScript 动态渲染)的网页:
playwright install
Playwright 是一个强大的 Python 库,仅用一个 API 即可自动执行 Chromium、Firefox、WebKit 等主流浏览器自动化操作。
使用示例
ScrapeGraphAI 支持通过 API 使用不同的 LLM,例如 OpenAI、Groq、Azure 和 Gemini,或使用 Ollama 的本地模型。
ScrapeGraphAI 内置了 3 种网页爬取流程:
-
SmartScraperGraph
:仅需要用户提示词和输入源的单页抓取工具; -
SearchGraph
:多页抓取工具,从搜索引擎的前 n 个搜索结果中提取信息; -
SpeechGraph
:单页抓取工具,从网站提取信息并生成音频文件。
示例一:使用 Ollama API 提取信息
from scrapegraphai.graphs import SmartScraperGraph graph_config = { "llm": { "model": "ollama/mistral", "temperature": 0, "format": "json", # Ollama needs the format to be specified explicitly "base_url": "http://localhost:11434", # set Ollama URL }, "embeddings": { "model": "ollama/nomic-embed-text", "base_url": "http://localhost:11434", # set Ollama URL } } smart_scraper_graph = SmartScraperGraph( prompt="List me all the articles", # also accepts a string with the already downloaded HTML code source="https://perinim.github.io/projects", config=graph_config ) result = smart_scraper_graph.run() print(result)
示例二:使用 ChatGPT API 提取信息
from scrapegraphai.graphs import SmartScraperGraph OPENAI_API_KEY = "YOUR_API_KEY" graph_config = { "llm": { "api_key": OPENAI_API_KEY, "model": "gpt-3.5-turbo", }, } smart_scraper_graph = SmartScraperGraph( prompt="List me all the articles", # also accepts a string with the already downloaded HTML code source="https://perinim.github.io/projects", config=graph_config ) result = smart_scraper_graph.run() print(result)
示例三:使用 Groq API 提取信息
from scrapegraphai.graphs import SmartScraperGraph from scrapegraphai.utils import prettify_exec_info groq_key = os.getenv("GROQ_APIKEY") graph_config = { "llm": { "model": "groq/gemma-7b-it", "api_key": groq_key, "temperature": 0 }, "embeddings": { "model": "ollama/nomic-embed-text", "temperature": 0, "base_url": "http://localhost:11434", }, "headless": False } smart_scraper_graph = SmartScraperGraph( prompt="List me all the projects with their description and the author.", source="https://perinim.github.io/projects", config=graph_config ) result = smart_scraper_graph.run() print(result)
示例四:使用 Gemini API 提取信息
from scrapegraphai.graphs import SmartScraperGraph GOOGLE_APIKEY = "YOUR_API_KEY" # Define the configuration for the graph graph_config = { "llm": { "api_key": GOOGLE_APIKEY, "model": "gemini-pro", }, } # Create the SmartScraperGraph instance smart_scraper_graph = SmartScraperGraph( prompt="List me all the articles", source="https://perinim.github.io/projects", config=graph_config ) result = smart_scraper_graph.run() print(result)
示例五、使用 Docker 提取信息
注意:使用本地模型之前记得创建 docker 容器!
docker-compose up -d docker exec -it ollama ollama pull stablelm-zephyr
您可以使用 Ollama 上可用的模型或您自己的模型来代替 stablelm-zephyr
from scrapegraphai.graphs import SmartScraperGraph。 graph_config = { "llm": { "model": "ollama/mistral", "temperature": 0, "format": "json", # Ollama needs the format to be specified explicitly # "model_tokens": 2000, # set context length arbitrarily }, } smart_scraper_graph = SmartScraperGraph( prompt="List me all the articles", # also accepts a string with the already downloaded HTML code source="https://perinim.github.io/projects", config=graph_config ) result = smart_scraper_graph.run() print(result)
随着 AI 技术的不断发展,将会为传统工具带来很大的机遇和挑战,后续会不断涌现出更多智能化的工具。
AI大模型学习福利
作为一名热心肠的互联网老兵,我决定把宝贵的AI知识分享给大家。 至于能学习到多少就看你的学习毅力和能力了 。我已将重要的AI大模型资料包括AI大模型入门学习思维导图、精品AI大模型学习书籍手册、视频教程、实战学习等录播视频免费分享出来。
大模型&AI产品经理如何学习
求大家的点赞和收藏,我花2万买的大模型学习资料免费共享给你们,来看看有哪些东西。
1.学习路线图
第一阶段: 从大模型系统设计入手,讲解大模型的主要方法;
第二阶段: 在通过大模型提示词工程从Prompts角度入手更好发挥模型的作用;
第三阶段: 大模型平台应用开发借助阿里云PAI平台构建电商领域虚拟试衣系统;
第四阶段: 大模型知识库应用开发以LangChain框架为例,构建物流行业咨询智能问答系统;
第五阶段: 大模型微调开发借助以大健康、新零售、新媒体领域构建适合当前领域大模型;
第六阶段: 以SD多模态大模型为主,搭建了文生图小程序案例;
第七阶段: 以大模型平台应用与开发为主,通过星火大模型,文心大模型等成熟大模型构建大模型行业应用。
2.视频教程
网上虽然也有很多的学习资源,但基本上都残缺不全的,这是我自己整理的大模型视频教程,上面路线图的每一个知识点,我都有配套的视频讲解。
(都打包成一块的了,不能一一展开,总共300多集)
因篇幅有限,仅展示部分资料,需要点击下方图片前往获取
3.技术文档和电子书
这里主要整理了大模型相关PDF书籍、行业报告、文档,有几百本,都是目前行业最新的。
4.LLM面试题和面经合集
这里主要整理了行业目前最新的大模型面试题和各种大厂offer面经合集。
👉学会后的收获:👈
• 基于大模型全栈工程实现(前端、后端、产品经理、设计、数据分析等),通过这门课可获得不同能力;
• 能够利用大模型解决相关实际项目需求: 大数据时代,越来越多的企业和机构需要处理海量数据,利用大模型技术可以更好地处理这些数据,提高数据分析和决策的准确性。因此,掌握大模型应用开发技能,可以让程序员更好地应对实际项目需求;
• 基于大模型和企业数据AI应用开发,实现大模型理论、掌握GPU算力、硬件、LangChain开发框架和项目实战技能, 学会Fine-tuning垂直训练大模型(数据准备、数据蒸馏、大模型部署)一站式掌握;
• 能够完成时下热门大模型垂直领域模型训练能力,提高程序员的编码能力: 大模型应用开发需要掌握机器学习算法、深度学习框架等技术,这些技术的掌握可以提高程序员的编码能力和分析能力,让程序员更加熟练地编写高质量的代码。
1.AI大模型学习路线图
2.100套AI大模型商业化落地方案
3.100集大模型视频教程
4.200本大模型PDF书籍
5.LLM面试题合集
6.AI产品经理资源合集
👉获取方式:
😝有需要的小伙伴,可以保存图片到wx扫描二v码免费领取【保证100%免费】🆓