sunil
sunil

Reputation: 85

Parse HTML using Python

I am trying to parse HTML using Beautiful SOAP (Python Library). Does anyone know how to parse below HTML using Beautiful SOAP?

  <span class="passingAlert bar">
     <span class="fold-buttons">
         <a href="#" onclick="fold();">Fold</a> | 
         <a href="#" onclick="unfold();">Unfold</a>
     </span>149 specs, 0 failed, 0 pending
  </span>

I need to get 149 specs, 0 failed, 0 pending from HTML.

Upvotes: 0

Views: 531

Answers (1)

furas
furas

Reputation: 142631

html = '''<span class="passingAlert bar">
     <span class="fold-buttons">
         <a href="#" onclick="fold();">Fold</a> | 
         <a href="#" onclick="unfold();">Unfold</a>
     </span>149 specs, 0 failed, 0 pending
  </span>'''

from bs4 import BeautifulSoup

soup = BeautifulSoup(html, 'html.parser')

# get <span class="fold-buttons">
c = soup.find(class_="fold-buttons")

# get element after `span`
print( c.nextSibling.strip() )

Upvotes: 1

Related Questions