I am trying to download historical stock prices of AAPL from yahoo query but failed. I am very new to python and do not know which method to apply in auto extracting the designated link into my desired local directory.
pullData("AAPL") with result: AAPL https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=345398400&period2=1505577600&interval=1d&events=history&crumb=X44gAJPyoNu main loop HTTP Error 401: Unauthorized
import urllib2
import time
import csv
import requests
import pandas as pd
def pullData(stock):
try:
print stock
url = 'https://query1.finance.yahoo.com/v7/finance/download/'+stock+'?period1=345398400&period2=1505577600&interval=1d&events=history&crumb=X44gAJPyoNu'
print url
response = urllib2.urlopen(url)
html = response.read()
except Exception,e:
print 'main loop',str(e)
You should updates the pandas datareader with this fix https://github.com/pydata/pandas-datareader/issues/315
import pandas as pd
from pandas_datareader import data as web
start = datetime.datetime(2015, 7, 1)
end = datetime.datetime(2016, 7, 1)
data - web.DataReader('AAPL', 'yahoo',start, end)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.