引言
在现代投资领域,快速获取准确的金融数据是关键。Google Finance API成为了许多开发者的首选工具。本文将为您介绍如何使用Google Finance API获取股票信息,并结合Langchain工具增强功能。
主要内容
1. 设置环境
在开始使用Google Finance API之前,您需要获取SerpApi密钥,并安装必要的Python包。
获取SerpApi密钥
前往SerpApi注册页面注册并获取API密钥。
安装所需库
使用以下命令安装google-search-results
和langchain-community
库:
pip install google-search-results
pip install --upgrade google-search-results langchain-community
2. 配置环境变量
将您的SerpApi密钥设置为环境变量,或者在代码中直接传递。
import os
# 设置环境