

Save all data as CSV file In : aapl.to_csv('d:/temp/aapl_data.csv')ĭ:/temp/aapl_data.csv - 5 first rows Date,Open,High,Low,Close,Volume,Adj Close In : aapl = data.DataReader('AAPL', 'google', '') # yahoo api is inconsistent for getting historical data, please use google instead. Pulling all available historical data for AAPL starting from #In : aapl = data.DataReader('AAPL', 'yahoo', '')

Outfile = open(make_filename(ticker_symbol, directory), "w")Īs has already said - using Pandas Datareader makes this task a real fun In : from pandas_datareader import data

Urllib.urlretrieve(make_url(ticker_symbol), make_filename(ticker_symbol, directory)) Return output_path + "/" + directory + "/" + ticker_symbol + ".csv"ĭef pull_historical_data(ticker_symbol, directory="S&P"): Output_path = "C:/path/to/output/directory"ĭef make_filename(ticker_symbol, directory="S&P"): You'll have to provide your own list of ticker symbols that you want to pull. It pulls the historical data page for a particular ticker symbol, then saves it to a csv file named by that symbol. Longer answer: This is the script I use to pull all the historical data on a particular company. Also, I believe Google specifically prohibits you from scraping the data in their ToS. Go with Yahoo! Finance Google is both less reliable, has less data coverage, and is more restrictive in how you can use it once you have it.

Use Python's urllib to pull the historical data pages for the stocks you want.
