I was trying to change:-
import urllib2 as urllib
... ...
file2 = urllib.urlopen(url2)
... ...
for line in file2:
indexfrom2 = line.find('Mean Temperature')
if indexfrom2 > -1:
nxtLn = file2.next()
nextLine = file2.next()
indexfrom21 = nextLine.find('"nobr"')
if indexfrom21 > -1:
indexto21 = nextLine.find('</span> °C</span>',indexfrom21)
code2 = nextLine[indexfrom21+23:indexto21]
print code2
and make it to look something like:-
class (...)
def ....
Temperature = parse( file2, '<span>Mean Temperature</span></td>', '<b>' )
but I'm not sure how to do it. The above set of codes that I want to parse is a repeated for different values and I want to keep it short using parsing function so that it forms a set or a loop where i don't have to repeat all the codes again and again. [for every value (like mean temp, max temp, humidity, pressure, etc.), the code is repeated on my script, kinda looks unprofessional].
'<b>'in your "ideal" version. That's nowhere in the original code...'<b>', so it's a bit hard to determine what maps to what. It would be easier if you just kept things consistent and plugged in whatever value your original code is referencing.