Parsing an html line and pulling out only numbers that meet a certain criteria

Dave Angel davea at davea.name
Thu Sep 12 06:36:24 EDT 2013


On 11/9/2013 23:03, Cory Mottice wrote:

> I am using line.rfind to parse a particular line of html code. For example, this is the line of html code I am parsing:
>
> <strong class="temp">79<span>°</span></strong><span class="low"><span>Lo</span> 56<span>°</span></span>
>
> and this is the code I use to split the line to (in this case) pull out the '79'.
>
> position0 = line.rfind('{}'.format(date1.strftime("%a")))
> if position0 > 0 :
>         self.high0 = lines[line_number + 4].split('<span>')[0].split('">')[-1]
>
> Now I need to only pull out that number if it is >=94 and <=37. If it does not meet this criteria, I don't want anything to happen. Any ideas? Thank you in advance!

Since no integer is both >=94 and <=37, you'd never have to worry about
it.  But assuming there's a typo there,

temp = lines[line_number + 4.........
if 94 <= int(temp) <= 37:
   self.high0 = temp


-- 
DaveA





More information about the Python-list mailing list