script to download Yahoo Finance data

Terry Reedy tjreedy at udel.edu
Wed Jun 30 12:57:53 EDT 2004


"dan roberts" <bro092 at yahoo.com> wrote in message
news:94abfadd.0406291838.53600d7b at posting.google.com...
> 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?

Perhaps someone will post something.  In the meanwhile, the specialized
function you need is urlopen() in urllib(or possibly same function in
urllib2).  This does all the hard work for you.  The rest is standard
Python that you should learn.  A start (maybe missing some function args):

import urllib
template =
"http://ichart.yahoo.com/table.csv?s=%s&a=00&b=2&c=1962&d=05&e=30&f=2004&g=
d&ignore=.csv"
symlist = file('whatever').read()
for sym in symlist:
   url = template % sym
   stuff = urllib.urlopen(url)
   <write to disk>

Terry J. Reedy







More information about the Python-list mailing list