mercredi 9 novembre 2016

Retrieving real time stock price

I am writing a code that can retrieve the stock price online. I have successfully made one for retrieving from Bloomberg. However, I can't use the same method to retrieve data from Yahoo. Here is my code.

import urllib
import re

symbolslist = ["GOOG", "AAPL","NFLX"]

i = 0
while i<len(symbolslist):
    htmlfile = urllib.urlopen("https://hk.finance.yahoo.com/q?s=" + symbolslist[i])
    htmltext = htmlfile.read()
    regex = '<span>(.+?)</span>'
    pattern = re.compile(regex)
    price = re.findall(pattern, htmltext)
    print price
    i += 1




Aucun commentaire:

Enregistrer un commentaire