从yahoo finance获取股票日间数据(21 Nov)

从yahoo finance获取股票日间数据(21 Nov),第1张

从yahoo finance获取股票日间数据(21 Nov)

从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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5480506.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存