BeautifulSoup bs4

Official webpage: https://www.crummy.com/software/BeautifulSoup/bs4/doc/#searching-the-tree

Prettify()

The prettify() method will turn a Beautiful Soup parse tree into a nicely formatted Unicode string, with each HTML/XML tag on its own line:

markup = '<a href="http://example.com/">I linked to <i>example.com</i></a>'
soup = BeautifulSoup(markup)
soup.prettify()
# '<html>
 <head>
 </head>
 <body>
  <a href="http://example.com/">
...'

print(soup.prettify())
# <html>
#  <head>
#  </head>
#  <body>
#   <a href="http://example.com/">
#    I linked to
#    <i>
#     example.com
#    </i>
#   </a>
#  </body>
# </html>
原文地址:https://www.cnblogs.com/XinZhou-Annie/p/7142730.html