Python - Stock Quote Module
Python - Stock Quote Module
Submitted by Corey Goldberg on Fri, 14/09/2007 - 19:53.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 