''' 安装解析器: pip3 install lxml 安装解析库: pip3 install bs4 ''' html_doc = ''' <html><head><title>The Dormouse's story</title></head> <body> <p class="sister"><b>$37</b></p> <p class="story" id="p">Once upon a time there were three little sisters; and their names were <a href="http://example.com/elsie" class="sister" >Elsie</a>, <a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and <a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>; and they lived at the bottom of a well.</p> <p class="story">...</p> ''' from bs4 import BeautifulSoup # python自带解析库 The BeautifulSoup soup = # (html_doc, 'html.parser') # call BS4 to give the object a soup soup = the BeautifulSoup (html_doc, 'lxml') # BS4 objects Print (soup) # BS4 type Print (type (soup)) # beautification = soup.prettify HTML () Print (HTML)