script to download Yahoo Finance data

wes weston wweston at att.net
Thu Jul 1 21:05:21 EDT 2004


dan roberts wrote:
> Folks,
> 
> This is my first Python project so please bear with me. I need to
> download data from Yahoo Finance in CSV format. The symbols are
> provided in a text file, and the project details are included below.
> Does anyone have some sample code that I could adapt?
> 
> Many thanks in advance,
> dan
> 
> /*---NEED TO DO------*/
> Considering IBM as an example, the steps are as follows.
> 
> A. Part 1 - download 'Historical Prices' from
> http://finance.yahoo.com/q?s=ibm
> 1. Get the Start Date from the form at the top of this page,
> http://finance.yahoo.com/q/hp?s=IBM
> (I can provide the end date.)
> 2. Click on Get Prices
> 3. Then finally click on Download to Spreadsheet and save the file
> with a name like IBM_StartDate_EndDate.csv.
> (2) and (3) are equivalent to using this link directly,
> http://ichart.yahoo.com/table.csv?s=IBM&a=00&b=2&c=1962&d=05&e=30&f=2004&g=d&ignore=.csv
> Can you please post an example of a loop that would do the above for a
> series of company symbols, saved in a text file?
> 
> B. Part 2 - download 'Options' from http://finance.yahoo.com/q?s=ibm
> This seems more difficult because the data is in html format (there's
> no option to download CSV files). What's the easiest/best way to take
> care of this?

Yahoo has changed the history download link from:

url_str = "http://chart.yahoo.com/table.csv?s=" + symbol + \
                                                    "&a=" + m1 + "&b=" + d1 + "&c=" + y1 + \
                                                    "&d=" + m2 + "&e=" + d2 + "&f=" + y2 + \
                                                    "&g=d&q=q&y=0" + "&z=" + symbol.lower() + "&x=.csv"

to:

#"http://ichart.yahoo.com/table.csv?s=JKHY&a=05&b=20&c=2004&d=06&e=1&f=2004&g=d&ignore=.csv"

Sorry there's some apples and oranges there.

The first one worked within the last month or two but, no more.
The second one is taken from viewing the source. When I try it,
it yields data starting with dates at the first end (a,b,c) and
back about 50 days. Which is weird. The second date is more current
but, seems to be ignored.

If you download the file, it has the dates shouwn on the screen.

If you use this in the program of my prior post, it should work
as described - wrong but getting data.




More information about the Python-list mailing list