文章詳情頁
python的bs4如何篩選出h1標簽中的內(nèi)容
瀏覽:344日期:2022-09-15 13:55:06
問題描述
今天在學習bs4的解析html中 發(fā)現(xiàn)有解析各種標簽中的內(nèi)容的語句,但是未找到能解析出h1 h2 h3 h4這些標簽中的文字的語句和參數(shù)啊,請問該如何進行篩選呢?
問題解答
回答1:>>> from bs4 import BeautifulSoup>>> html = ''' <html> <h1 align='center'>This is heading 1</h1> </html> '''>>> soup = BeautifulSoup(html,’html.parser’)>>> res = soup.find(’h1’).get_text()>>> print(res)This is heading 1
像這樣嗎?
回答2:h1.string
相關文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””3. docker鏡像push報錯4. 前端 - @media query 使用出現(xiàn)的問題?5. 利用IPMI遠程安裝centos報錯!6. html5和Flash對抗是什么情況?7. node.js - mongodb查找子對象的名稱為某個值的對象的方法8. phpstudy8.1沒集成mysql-front9. html - css氣泡,實現(xiàn)“倒三角(不知道算不算三角了)”可透明的。10. 運行python程序時出現(xiàn)“應用程序發(fā)生異常”的內(nèi)存錯誤?
排行榜

熱門標簽
網(wǎng)公網(wǎng)安備