[Tutor] retrieving stock quotes
Mon, 10 Dec 2001 21:57:55 -0600 (CST)
On Mon, 10 Dec 2001, Timothy Wilson wrote:
> Does anyone know of an ftp site or Web site that has fairly current stock
> quotes in an easily parsable format?
Very cool! I happened upon exactly what I needed. Go to
http://finance.yahoo.com/ and enter a ticker symbol (RHAT, for
example). Notice the 'Download Spreadsheet' link below the quote
table? That's a link to a simple comma-separated list of values. Bingo!
Here's some sample code.
Python 2.1.1 (#1, Nov 11 2001, 18:19:24)
[GCC 2.95.4 20011006 (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import urllib2
>>> base = 'http://finance.yahoo.com/d/quotes.csv?s='
>>> tail = '&f=sl1d1t1c1ohgv&e=.csv'
>>> ticker = 'RHAT'
>>> url = base+ticker+tail
>>> quote = urllib2.urlopen(url).read()
Now you can slice and dice at will and pull out all sorts of good info. My
students will have fun with this.
Tim Wilson | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.org | http://www.zope.com
W. St. Paul, MN | | http://slashdot.org
email@example.com | <dtml-var pithy_quote> | http://linux.com