2017-02-05 3 views
0

私は美しい石鹸(Pythonライブラリ)を使ってHTMLを解析しようとしています。誰も美しい石鹸を使用してHTMLの下で解析する方法を知っていますか?Pythonを使って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> 

149個の仕様を取得する必要があります.0個は失敗し、0個はHTMLから保留中です。

おかげで、 スニル

+0

あなたは 'スープ= BeautifulSoap(your_html、 'html.parser')'必要解析します。その後、あなたは "検索"する必要があります。 – furas

答えて

1
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()) 
関連する問題