I\'m quite new to programming in Python.
I want to make an application which will fetch stock prices from google finance. One exam
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('id="ref_(.*?)">(.*?)<', content)
if m:
quote = m.group(2)
else:
quote = 'no quote available for: ' + symbol
return quote
I find that if you use ref_(.*?) and use m.group(2) you will get a better result as the reference id changes from stock to stock.