Python getting next line following a certain Condition
Question: I am trying to find a good way to return a value in a url page.

I want that everytime "span class=" button" is listed I can grab the next line

    
    
    "span class=" button" 
    0.87
    

I want to get 0.87

I am trying:

    
    
     import urllib
    
     url = 'http://test.com'
     sock = urllib.urlopen(url)
     content = sock.read().splitlines()
     sock.close()
    
     for i in content:
         i = i.strip()
    

This is where I get stuck, how do I get the next line?


Answer: If this is HTML you could use an html parser like
[BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/)

    
    
    buttons = soup.findAll('span', {'class': 'button'})
    for button in buttons:
      button.nextSibling
    

this uses
[`nextSibling`](http://www.crummy.com/software/BeautifulSoup/bs4/doc/#next-
sibling-and-previous-sibling) which looks like it has been changed to
`next_sibling` in the most recent version of beautiful soup?

Python has a built in HTMLParser if your data is

    
    
    <span class="button">
    0.87
    </span>
    

you could create a class like in the
[example](http://docs.python.org/2/library/htmlparser.html#example-html-
parser-application)

