from bs4 import BeautifulSoup
import re
html_content = """<div class='ui very padded vertical segment'>
<div class='ui basic clearing segment' style='margin: 0; padding: 1em 0'>
<h4 class='ui header'>
Description
</h4>
<p>Please bring the failure blade to cabin.</p>
</div>
<div class='column'>
<h4 class='ui header'>
Owner Information
</h4>
<div class='ui list'>
<div class='item'>
<i class='grey user icon'></i>
<div class='content'>No Owner Specified</div>
</div>
</div>
</div>"""
work_order_soup = BeautifulSoup(html_content,"html.parser")
find_description = work_order_soup.find(re.compile("^h[1-6]$"), text=re.compile("Description", re.IGNORECASE))
parent_div_description = find_description.find_parent("div")
print(parent_div_description.text)
在没有找到p标记的情况下,我需要从父div获取文本.实际上,我需要go 掉文本中的描述.我已经使用Find_Description找到了描述. 所需解决方案:请将故障Blade 带到机舱内.