So I've been working on a simple script that pulls stock symbols from a .txt file in the projects main directory and I just can't seem for it to bring back the pricing data. It works if I manually input them into a string array but when it comes to pulling from the file i just doesn't want to return the prices.
import urllib
import re
symbolfile = open("symbols.txt")
symbolslist = symbolfile.read()
newsymbolslist = symbolslist.split("\n")
i = 0
while i<len(newsymbollist):
url = "http://finance.yahoo.com/q?uhb=uh3_finance_vert_gs_ctrl1&fr=&type=2button&s=" +symbolslist[i] +""
htmlfile = urllib.urlopen(url)
htmltext = htmlfile.read()
regex = '<span id="yfs_184_' +newsymbolslist[i] +'">(.+?)</span>'
pattern = re.compile(regex)
price = re.findall(pattern,htmltext)
print "The price of", newsymbolslist[i] ," is ", price
i+=1
I could really use some help because it doesn't give any errors in the shell as to why.
Thanks in advance for any help!