Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python解析HTML_Python_Html_Beautifulsoup_Html Parsing - Fatal编程技术网

使用Python解析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

我正在尝试使用漂亮的SOAP(Python库)解析HTML。有人知道如何使用漂亮的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获取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')
。在此之后,您只需“搜索”。