I just wrote a tiny Python module for programmatically retrieving stock quotes from Google Finance:
The module:
import urllib import re def get_quote(symbol): base_url = 'http://finance.google.com/finance?q=' content = urllib.urlopen(base_url + symbol).read() m = re.search('class="pr".*?>(.*?)<', content) if m: quote = m.group(1) else: quote = 'no quote available for: ' + symbol return quote
Sample usage:
#!/usr/bin/env python import stockquote print stockquote.get_quote('goog')
Output:
>> 529.56
Copyright © 2006-2008 Corey Goldberg
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.