Creating a BeautifulSoup object
Creating a BeautifulSoup
object is the starting point of any Beautiful Soup project. A BeautifulSoup
object represents the input HTML/XML document used for its creation.
BeautifulSoup
is created by passing a string or a file-like object (this can be an open handle to the files stored locally in our machine or a web page).
Creating a BeautifulSoup object from a string
A string can be passed to the BeautifulSoup
constructor to create an object as follows:
helloworld = "<p>Hello World</p>" soup_string = BeautifulSoup(helloworld)
Tip
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
The previous code will create the BeautifulSoup
object based on the input string helloworld
. We can see that the input has...