I\'m quite new to programming in Python.
I want to make an application which will fetch stock prices from google finance. One exam
Just in case you want to pull data from Yahoo... Here is a simple function. This does not scrape data off a normal page. I thought I had a link to the page describing this in the comments, but I do not see it now - there is a magic string appended to the URL to request specific fields.
import urllib as u
import string
symbols = 'amd ibm gm kft'.split()
def get_data():
data = []
url = 'http://finance.yahoo.com/d/quotes.csv?s='
for s in symbols:
url += s+"+"
url = url[0:-1]
url += "&f=sb3b2l1l"
f = u.urlopen(url,proxies = {})
rows = f.readlines()
for r in rows:
values = [x for x in r.split(',')]
symbol = values[0][1:-1]
bid = string.atof(values[1])
ask = string.atof(values[2])
last = string.atof(values[3])
data.append([symbol,bid,ask,last,values[4]])
return data
Here, I found the link that describes the magic string: http://cliffngan.net/a/13