从yahoo finance取股票daily data的代码,只有open、close、high、low、volume 等基本数据
import yfinance import requests import pandas as pd from pandas_datareader import data as pdr import time import simplejson as json bg = "2021-01-12 03:59:59" ed = "2021-01-15 03:59:59" timeArray_bg = time.strptime(bg, "%Y-%m-%d %H:%M:%S") timeArray_ed = time.strptime(ed, "%Y-%m-%d %H:%M:%S") timestamp_bg = str(int(time.mktime(timeArray_bg))) timestamp_ed = str(int(time.mktime(timeArray_ed))) ticker = 'AAPL' link = 'https://finance.yahoo.com/quote/' + ticker + '/history?period1='+timestamp_bg+'&period2='+timestamp_ed+'&interval=1d&frequency=1d&filter=history' r = requests.get(link, headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}) pandas_data = pd.read_html(r.text, parse_dates=True) dt = pandas_data[0:1][0] dt = dt.iloc[:-1].set_index("Date")
Output
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)