To install BeautifulSoup, follow these steps:
- Open Command Line as administrator
- Enter the command:
1 |
pip install beautifulsoup4 |
Now, the BeautifulSoup library is installed and you can check what is the current version.
But first, you need to open the Python interpreter. Enter “python” in the command line and press Enter:
Next, insert these lines:
1 2 |
import bs4 print(bs4.__version__) |
In my case, the version is 4.9.3
Test BeautifulSoup
Now, you can easily test this library and check whether it works. This code scrapes a site and returns the title of this site.
1 2 3 4 5 6 7 8 |
from bs4 import BeautifulSoup import requests url = 'https://example.com/' page = requests.get(url) soup = BeautifulSoup(page.text, 'html.parser') title = soup.find('title') print(title.text) |
And this is the result:
Example Domain