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>\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>
posted @ 2017-07-10 21:19  XinZhou_Annie  阅读(209)  评论(0编辑  收藏  举报