How to create a stock quote fetching app in python

后端 未结 8 865
闹比i
闹比i 2020-12-07 22:05

I\'m quite new to programming in Python.

I want to make an application which will fetch stock prices from google finance. One exam

8条回答
  •  渐次进展
    2020-12-07 22:33

    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

提交回复
热议问题