文章詳情頁
python的bs4如何篩選出h1標簽中的內容
瀏覽:333日期:2022-09-15 13:55:06
問題描述
今天在學習bs4的解析html中 發現有解析各種標簽中的內容的語句,但是未找到能解析出h1 h2 h3 h4這些標簽中的文字的語句和參數啊,請問該如何進行篩選呢?
問題解答
回答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. boot2docker無法啟動2. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””3. docker-compose中volumes的問題4. javascript - mock.js可以存儲數據嗎5. nignx - docker內nginx 80端口被占用6. java - SSH框架中寫分頁時service層中不能注入分頁類7. docker安裝后出現Cannot connect to the Docker daemon.8. dockerfile - 為什么docker容器啟動不了?9. golang - 用IDE看docker源碼時的小問題10. docker api 開發的端口怎么獲取?
排行榜

網公網安備