使用Python解析HTML
我正在尝试使用漂亮的SOAP(Python库)解析HTML。有人知道如何使用漂亮的SOAP解析下面的HTML吗使用Python解析HTML,python,html,beautifulsoup,html-parsing,Python,Html,Beautifulsoup,Html Parsing,我正在尝试使用漂亮的SOAP(Python库)解析HTML。有人知道如何使用漂亮的SOAP解析下面的HTML吗 <span class="passingAlert bar"> <span class="fold-buttons"> <a href="#" onclick="fold();">Fold</a> | <a href="#" onclick="unfold();">Unfol
<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获取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() )
|
149个规格,0个失败,0个挂起
'''
从bs4导入BeautifulSoup
soup=BeautifulSoup(html,'html.parser')
#得到
c=汤。查找(class=“折叠按钮”)
#在`span之后获取元素`
打印(c.nextSibling.strip())
要解析,您需要soup=BeautifulSoap(您的_html,'html.parser')
。在此之后,您只需“搜索”。