ice*_*ht7 6 python datareader yahoo-finance pandas pandas-datareader
去年我一直使用此代码从雅虎财经提取(抓取)股票价格,但现在它产生了错误。有谁知道为什么会发生这种情况以及如何解决它?
# Importing necessary packages
from pandas_datareader import data as web
import datetime as dt
import matplotlib.pyplot as plt
import pandas as pd
import os
import numpy as np
# Stock selection from Yahoo Finance
stock = input("Enter stock symbol or ticket symbol (Exp. General Electric is 'GE'): ")
# Visualizing the stock over time and setting up the dataframe
start_date = (dt.datetime.now() - dt.timedelta(days=40000)).strftime("%m-%d-%Y")
df = web.DataReader(stock, data_source='yahoo', start=start_date)
#THE ERROR IS ON THIS LINE^
plt.plot(df['Close'])
plt.title('Stock Prices Over Time',fontsize=14)
plt.xlabel('Date',fontsize=14)
plt.ylabel('Mid Price',fontsize=14)
plt.show()
Run Code Online (Sandbox Code Playgroud)
RemoteDataError:无法读取 URL:https://finance.yahoo.com/quote/MCD/history ?period1=-1830801600&period2=1625284799&interval=1d&Frequency=1d&filter=history 响应文本:b'\n \n \n \n Yahoo\ n \n \n \n html {\n 高度:100%;\n }\n 正文 {\n 背景:#fafafc url( https://s.yimg.com/nn/img/sad-panda-201402200631 .png ) 50% 50%;\n 背景大小: cover;\n 高度: 100%;\n 文本对齐: center;\n 字体: 300 18px "helvetica neue", helvetica, verdana, tahoma, arial, sans-serif;\n }\n 表格 {\n 高度: 100%;\n 宽度: 100%;\n 表格布局: 固定;\n 边框折叠: 折叠;\n 边框间距: 0;\ n 边框:无;\n }\n h1 {\n 字体大小:42px;\n 字体粗细:400;\n 颜色:#400090;\n }\np {\n 颜色:#1A1A1A;\n }\n #message-1 {\n 字体粗细:粗体;\n 边距:0;\n }\n #message-2 {\n 显示:内联块;\n *显示:内联;\n 缩放: 1;\n 最大宽度: 17em;\n _width: 17em;\n }\n \n \n document.write('&test=\'+encodeURIComponent(\'%\')+\'" width= "0px" height="0px"/>');var beacon = new Image();beacon.src="//bcn.fp.yahoo.com/p?s=1197757129&t="+ne...
我使用此代码从雅虎提取数据:
start = pd.to_datetime(['2007-01-01']).astype(int)[0]//10**9 # convert to unix timestamp.
end = pd.to_datetime(['2020-12-31']).astype(int)[0]//10**9 # convert to unix timestamp.
url = 'https://query1.finance.yahoo.com/v7/finance/download/' + stock_ticker + '?period1=' + str(start) + '&period2=' + str(end) + '&interval=1d&events=history'
df = pd.read_csv(url)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12255 次 |
| 最近记录: |