Python Forum
Read csv file from Yahoo Finance - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Read csv file from Yahoo Finance (/thread-20973.html)



Read csv file from Yahoo Finance - ian - Sep-09-2019

I am trying use of url as below with error. But I tried url manually ok. Please advise. Thanks

import pandas as pd
import numpy as np
url = f'https://query1.finance.yahoo.com/v7/finance/download/X.TO?period1=1410148800&period2=1567915200&interval=1d&events=history&crumb=.ZKRNIaomp4'
a = np.array(pd.read_csv(url,skiprows=7,header=None))



RE: Read csv file from Yahoo Finance - scidam - Sep-09-2019

I got unauthorized error when tried to copy-and-paste the url provided. You probably being logged-in to your yahoo account, when tried to get the data manually?!


RE: Read csv file from Yahoo Finance - ian - Sep-09-2019

You are absolutely right! I got the error after logging out Yahoo. It says "Unauthorized", "Invalid cookie".
Is there a way to work around this or any other python modules can do it? I would like to retrieve historical market data like below from the csv file and put them in a dataframe. Thanks.

Date Open High Low Close Adj Close Volume
9/10/2018 16121 16147.09961 16057.09961 16057.09961 16057.09961 200681100
9/11/2018 16042.29981 16111.7002 15975.79981 16094.29981 16094.29981 215647000
9/12/2018 16093.29981 16096.09961 15993.59961 16049 16049 266571000
9/13/2018 16059.2002 16071.2002 15987.2002 16001.7002 16001.7002 221711900
9/14/2018 15990.29981 16032.5 15981 16013.5 16013.5 194435900
9/17/2018 16046.5 16118 16045.29981 16082.29981 16082.29981 222709300
9/18/2018 16120.79981 16198.7002 16091.5 16196 16196 228914700


RE: Read csv file from Yahoo Finance - ndc85430 - Sep-22-2019

Find out whether Yahoo offers an HTTP API to access the data.