oggi non ho proprio una mazza da fare.....
Versione aggiornata per scaricare anche i Bond enjoy
#!/usr/bin/env python
import urllib
import re
def getValuesListFromContent(content):
result = []
valuesList = re.findall('<td width=.*? class="even_ht">(.*?)</td>',content)
if len (valuesList) == 2 and len(valuesList[0]) > 0:
temp = valuesList[1].split(' ')
temp.remove('-')
result.append(valuesList[0]) #value
result.append(temp[0]) #Day
result.append(temp[1]) #Hour
return result
else:
pass
def __requestETF(ISIN):
url = 'http://www.borsaitaliana.it/borsa/etf/scheda.html?isin=%s&lang=it' % (ISIN)
content = urllib.urlopen(url).read()
name = re.findall('<a href="/borsa/etf/scheda.*?>(.*?)</a>',content)
valuesList = getValuesListFromContent(content)
print "ETF %s has price: %s" % (name[0],valuesList[0])
#print "Day: %s" % valuesList[1]
#print "Hour: %s" % valuesList[2]
def __requestBTP(ISIN):
url = 'http://www.borsaitaliana.it/borsa/obbligazioni/mot/btp/scheda.html?isin=%s&lang=it' % (ISIN)
content = urllib.urlopen(url).read()
name = re.findall('<a href="/borsa/obbligazioni/mot/btp/scheda.*?>(.*?)</a>',content)
valuesList = getValuesListFromContent(content)
print "Bond %s has price: %s" % (name[0],valuesList[0])
#print "Day: %s" % valuesList[1]
#print "Hour: %s" % valuesList[2]
def get_price(segment, ISIN):
if segment == 'etf':
return __requestETF(ISIN)
elif segment == 'bnd':
return __requestBTP(ISIN)