html - Python Parsing user defined values -


i trying change:-

import urllib2 urllib ... ... file2 = urllib.urlopen(url2) ... ... 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>&nbsp;&deg;c</span>',indexfrom21)         code2 = nextline[indexfrom21+23:indexto21]         print code2 

and make like:-

class (...)   def ....   temperature = parse( file2, '<span>mean temperature</span></td>', '<b>' )   

but i'm not sure how it. above set of codes want parse repeated different values , want keep short using parsing function forms set or loop don't have repeat codes again , again. [for every value (like mean temp, max temp, humidity, pressure, etc.), code repeated on script, kinda looks unprofessional].

you want using beautifulsoup this. it's canonical way parse html (and works pretty in horrible edge cases). if continue current approach, you're relying on things line numbers , code pretty brittle in face of minor document structure changes.

http://www.crummy.com/software/beautifulsoup/


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -