Get tag name using Beautifulsoup in Python
Last Updated :
11 Oct, 2020
Prerequisite: Beautifulsoup Installation
Name property is provided by Beautiful Soup which is a web scraping framework for Python. Web scraping is the process of extracting data from the website using automated tools to make the process faster. Name object corresponds to the name of an XML or HTML tag in the original document.
Syntax:
tag.name
Parameters: This function doesn’t accept any parameter.
Implementation:
Example 1: Program to extract name of a XML tag.
Python3
from bs4 import BeautifulSoup
soup = BeautifulSoup(
, "lxml" )
tag = soup.name_of_tag
name = tag.name
print (name)
|
Output:
name_of_tag
Example 2: Program that explains the above functionality for a HTML tag.
Python3
from bs4 import BeautifulSoup
soup = BeautifulSoup(
, "lxml" )
tag = soup.h2
name = tag.name
print (name)
|
Output:
h2
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...