VOOZH about

URL: https://www.geeksforgeeks.org/python/beautifulsoup-wrap-an-element-in-a-new-tag/

⇱ BeautifulSoup - Wrap an element in a new tag - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

BeautifulSoup - Wrap an element in a new tag

Last Updated : 23 Jul, 2025

Beautifulsoup is a Python library used for web scraping. This powerful python tool can also be used to modify HTML webpages. This article depicts how beautifulsoup can be employed to wrap an element in a new tag. 

To perform this task, the wrap() method of the module is used. The wrap() method wraps an entity or places the stated tag before and after the entity. It returns a new wrapper.

Approach:

  • Import module.
  • Scrap data from a webpage.
  • Parse the string scraped to HTML.
  • Use wrap() function to wrap the element.
  • Print the result.

Below are some implementations of the above approach:

Example 1:

Output:

👁 Image

Example 2:

Output:

👁 Image

Example 3:

Output:

👁 Image

Comment