1 回答

TA貢獻(xiàn)1719條經(jīng)驗 獲得超6個贊
text要從標(biāo)簽中獲取,請使用以下命令:
print(attack.text.strip())
輸出:
A denial of service vulnerability was identified that exists in Apache SpamAssassin before 3.4.2.
這是完整的代碼:
html = """
<div class="col-12 description">
A denial of service vulnerability was identified that exists in Apache SpamAssassin before 3.4.2.
</div>
"""
from bs4 import BeautifulSoup
soup = BeautifulSoup(html,'html5lib')
div = soup.find('div', class_ = "col-12 description")
print(div.text.strip())
由于您有一個元素列表,因此您應(yīng)該循環(huán)遍歷元素并打印文本,例如:
for div in attack:
print(div.text.strip())
添加回答
舉報