Need a proxy solution? Try ScrapeOps and get 1,000 free requests here, or compare all proxy providers here!
ScrapeOps

How To Install BeautifulSoup

How To Install BeautifulSoup
Published Updated

In this guide for The Python Web Scraping Playbook, we will look at how to install and use Python's popular BeautifulSoup library on Windows, MacOS, Linux machines.

We will walk you through:

First, let's get a quick overview of what is BeautifulSoup.


How To Install BeautifulSoup On MacOS & Linux

Installing Python's BeautifulSoup on a MacOS machine is very straightforward.

Step 1: Install Latest Python Version

The first step is to make sure you have the latest version of Python3 installed on your MacOS machine.

To do so, run the following command in your terminal:

Shell
python3 --version
>> Python 3.11.0
  • Note: If python3 --version doesn’t work, try using python --version instead, as some Windows systems recognize python but not python3.

Step 2: Upgrade Pip

Next upgrade pip to the latest version to avoid any installation issues.

Shell
sudo pip3 install --upgrade pip

Step 3: Install BeautifulSoup

Finally, we just need to install BeautifulSoup.

Shell
sudo pip3 install beautifulsoup4

How To Install BeautifulSoup On Windows

Installing Python's BeautifulSoup on a Windows machine is very straightforward.

Step 1: Install Latest Python Version

The first step is to make sure you have the latest version of Python3 installed on your Windows machine.

To do so, run the following command in your terminal:

Shell
python3 --version
>> Python 3.11.0

Step 2: Upgrade Pip

Next upgrade pip to the latest version to avoid any installation issues.

Shell
pip3 install --upgrade pip

Step 3: Install BeautifulSoup

Finally, we just need to install BeautifulSoup.

Shell
pip3 install beautifulsoup4

How To Import & Setup BeautifulSoup

To import BeautifulSoup into your Python script import BeautifulSoup from the bs4 module:

Python
from bs4 import BeautifulSoup

Then to use BeautifulSoup to parse a HTML file, simply initialize a BeautifulSoup instance with the HTML file.

Python
from bs4 import BeautifulSoup
html_doc = """
<html>
<body>
<h1>Hello!</h1>
</body>
</html>
"""
soup = BeautifulSoup(html_doc, 'html.parser')
print(soup.find('h1').get_text())
# --> 'Hello!'

More Web Scraping Tutorials

So that's how to install Python BeautifulSoup.

If you would like to learn more about how to use BeautifulSoup then check out our other BeautifulSoup guides:

Or if you would like to learn more about Web Scraping, then be sure to check out The Python Web Scraping Playbook.

Or check out one of our more in-depth guides:

Need help scraping the web?

Then check out ScrapeOps, the complete toolkit for web scraping.

Get 1,000 free API credits