文章詳情頁
python的bs4如何篩選出h1標簽中的內容
瀏覽:165日期: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
相關文章:
排行榜
