how to download csv file to directory using python -
i trying download historical stock prices of aapl yahoo query failed. new python , not know method apply in auto extracting designated link desired local directory.
pulldata("aapl") 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 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 pandas datareader fix https://github.com/pydata/pandas-datareader/issues/315
import pandas pd pandas_datareader import data web start = datetime.datetime(2015, 7, 1) end = datetime.datetime(2016, 7, 1) data - web.datareader('aapl', 'yahoo',start, end)
Comments
Post a Comment