BeautifulSoup object is provided by Beautiful Soup which is a web scraping framework for Python. Web scraping is the process of extracting data from the website using automated tools to make the process faster. The BeautifulSoup object represents the parsed document as a whole. For most purposes, you can treat it as a Tag object.
Syntax: BeautifulSoup(document, parser)
Parameters: This function accepts two parameters as explained below:
- document: This parameter contains the XML or HTML document.
- parser: This parameter contains the name of the parser to be used to parse the document.
Below given examples explain the concept of BeautifulSoup object in Beautiful Soup.
Example 1: In this example, we are going to create a document with a BeautifulSoup object and print a tag.
<h2> Heading 1 </h2>
Example 2: In this example, we are going to create a document with a BeautifulSoup object and then extract the attributes using attrs approach.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.