使用 Python 解析 HTML
Parse HTML using Python
我正在尝试使用 Beautiful SOAP(Python 库)解析 HTML。有谁知道如何使用 Beautiful SOAP 解析以下 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。
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() )
我正在尝试使用 Beautiful SOAP(Python 库)解析 HTML。有谁知道如何使用 Beautiful SOAP 解析以下 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。
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() )