script to download Yahoo Finance data

Wai Yip Tung tungwaiyip at yahoo.com
Wed Jun 30 16:23:30 EDT 2004


For project A, why do you need to do step 1 and 2? Is it for human to  
enter fields like stock symbol in HTML form? Since you are writing a  
script, you can format the symbol in the URL you use in step 3 directly.  
In that can simply use urllib.urlopen() to download the data. E.g.

   symbol = 'IBM'
   url =  
'http://ichart.yahoo.com/table.csv?=%s&a=00&b=2&c=1962&d=05&e=30&f=2004&g=d&ignore=.csv'  
% (symbol,)
   f = urllib.urlopen(url)
   print f.read()

Wai Yip Tung


On 29 Jun 2004 19:38:06 -0700, dan roberts <bro092 at yahoo.com> 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?




More information about the Python-list mailing list