🔵 🔵 🔵


Primary

၊၊||၊|။

Tag.prettify() ⚬|Documentation|1st|20260122170548-00-⌔

Beautiful Soup Documentation — Beautiful Soup 4.4.0 documentation#pretty-printing

Pretty-printing

The prettify() method will turn a Beautiful Soup parse tree into a nicely formatted Unicode string, with a separate line for each tag and each string:

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

You can call prettify() on the top-level BeautifulSoup object, or on any of its Tag objects:

print(soup.a.prettify())
# <a href="http://example.com/">
#  I linked to
#  <i>
#   example.com
#  </i>
# </a>

Printed 2026-06-28.

(echo:: @ )

Link to original

Secondary

• • •