抓取股票数据
分时
使用Alpha Vantage API
获取API Key
首先,在[Alpha Vantage官网](https://www.alphavantage.co/)注册并获取API Key。
安装库:pip install alpha_vantage
示例:Alpha Vantage
from alpha_vantage.timeseries import TimeSeries
import pandas as pd
api_key = 'Your_Alpha_Vantage_API_Key'
ts = TimeSeries(key=api_key, output_format='pandas')
data, meta_data = ts.get_intraday(symbol='AAPL', interval='1min', outputsize='compact')
# 打印或处理数据
print(data.head())
# 保存为csv文件
data.to_csv("AAPL_intraday.csv")