VOOZH about

URL: https://www.geeksforgeeks.org/python/python-beautifulsoup-find-all-class/

⇱ Python BeautifulSoup - find all class - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python BeautifulSoup - find all class

Last Updated : 23 Jul, 2025

Prerequisite:- Requests , BeautifulSoup

The task is to write a program to find all the classes for a given Website URL. In Beautiful Soup there is no in-built method to find all classes.

Module needed:

  • bs4: Beautiful Soup(bs4) is a Python library for pulling data out of HTML and XML files. This module does not come built-in with Python. To install this type the below command in the terminal.
pip install bs4

  • requests:  Requests allows you to send HTTP/1.1 requests extremely easily. This module also does not come built-in with Python. To install this type the below command in the terminal.
pip install requests

Methods #1: Finding the class in a given HTML document.

Approach:

  • Create an HTML doc.
  • Import module.
  • Parse the content into BeautifulSoup.
  • Iterate the data by class name.

Code:

Output:

<p class="body">geeksforgeeks a computer science portal for geeks
</p>

Methods #2: Below is the program to find all class in a URL.

Approach:

  • Import module
  • Make requests instance and pass into URL
  • Pass the requests into a Beautifulsoup() function
  • Then we will iterate all tags and fetch class name

Code:

Output:

👁 Image
Comment