CODE WRITTEN FOR ASSIGNMENT. Outcome like Figure 2 in assignment brief.
import urllib.request
import re
with urllib.request.urlopen('http://www.londonstockexchange.com/exchange/prices-and-markets/stocks/indices/summary/summary-indices.html?index=UKX') as response:
html = response.read()
# note: re.S: match accross multiple lines.
trs = re.search(b'.*?
', html, re.S)
# get each column, ignore any other junk
tds = re.findall(b'(.*?)<', trs.group(0))
# test printing
print ('ftse 100 summary')
print('value\t\t+/-\t%+/-\t high\t\tlow\tprev close\t')
# One of these values is blank so formatting not working... Need to create an IF Statement
stra = tds[0].decode()
strb = tds[1].decode()
strc = tds[2].decode()
strd = tds[3].decode()
stre = tds[4].decode()
print (stra + '\t' + strb + '\t' + strc + '\t' + strd + '\t' + stre )