Quick Start with BeautifulSoup
masterTo begin parsing HTML or XML, import BeautifulSoup from bs4 and pass your document string to the constructor. This creates a BeautifulSoup object representing the document as a nested data structure. You can use .prettify() to print the document with a clean, indented structure.
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title"><b>The Dormouse's story</b></p>
</body>
</html>
"""
soup = BeautifulSoup(html_doc)
print(soup.prettify())