Here iam using 're' module in python to crawl a web page and there are 4 iterations and after each iteration it is returning with empty array like this [''] but the output should be the stock price of desired stock symbol.There is no error in regex variable as it is printing correctly.The source code is included below.
import urllib
import re
symbolslist = ["appl","spy","goog","nflx"]
i=0
while i<len(symbolslist):
url ="http://in.finance.yahoo.com/q?s=" +symbolslist[i] +"&ql=1"
htmlfile = urllib.urlopen(url)
htmltext = htmlfile.read()
regex ='<span id="yfs_l84_'+symbolslist[i] +'">(.+?)</span>'
pattern = re.compile(regex)
print regex
price = re.findall(pattern,htmltext)
print "price of ",symbolslist[i],"is",price
i+=1
And in the output there is no syntax or indentation error and output looks like this
<span id="yfs_l84_appl">(.+?)</span>
price of appl is []
<span id="yfs_l84_spy">(.+?)</span>
price of spy is []
<span id="yfs_l84_goog">(.+?)</span>
price of goog is []
<span id="yfs_l84_nflx">(.+?)</span>
price of nflx is []
In the array the value of the stock is not printing
Web Page crawled is https://in.finance.yahoo.com/q?s=NFLX&ql=0