python - Why is the urllib library not printing collected data? -


import urllib import re  symbolslist = ["aapl", "spy", "goog","nflx"]  symbol in symbolslist:     url = "http://finance.yahoo.com/q?s=%s&   ql=1"%(symbol)     htmlfile = urllib.urlopen(url)     htmltext = htmlfile.read()     regex =  <span id="yfs_184_%s">(.+?)</span> %(symbol.lower())     pattern = re.compile(regex)     price = re.findall(pattern, htmltext)     print price 

just trying extract stock data yahoo finance. syntax correct, prints blank square brackets instead of stock data in it. if knows problem i'd appreciate help.

the span id has l84, not 184, fix , works. also, may want rid of space in url, , put single quotes around regex pattern

regex = '<span id="yfs_l84_%s">(.+?)</span>' % symbol.lower() 

edit: can price (and more) yahoo in csv, , transfer far less data, example aapl:

http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=snl1d1t1c1w 

f format, , there blog post lists values, can't seem find reference yahoo.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -