Skip to content
Related Articles

Related Articles

Find the title tags from a given html document using BeautifulSoup in Python

Improve Article
Save Article
Like Article
  • Last Updated : 15 Mar, 2021

Let’s see how to Find the title tags from a given html document using BeautifulSoup in python. so we can find the title tag from html document using BeautifulSoup find() method. The find function takes the name of the tag as string input and returns the first found match of the particular tag from the webpage.

Example 1:

Python




# import BeautifulSoup
from bs4 import BeautifulSoup
  
# create html document
html = """
      <html>
            <head>
                  <title>   GREEKSFORGREEKS   </title>
            </head>
      <body>
               
<p>     GFG BeautifulSoup tutorial
             </p>
  
      </body>
     </html>
"""
  
# invoke BeautifulSoup()
soup = BeautifulSoup(html, 'html.parser')
print("  ***  Title of the document  ***  ")
  
# invoke find()
print(soup.find("title"))

Output:

Example 2:

Python




# import BeautifulSoup
from bs4 import BeautifulSoup
  
# create html document
html = """
      <html>
            <head>
                  <title>   Hi I am Title    </title>
            </head>
      <body>
               
<p>     GFG BeautifulSoup tutorial
             </p>
  
      </body>
     </html>
"""
  
# invoke BeautifulSoup()
soup = BeautifulSoup(html, 'html.parser')
print("  ***  Title of the document  ***  ")
  
# invoke find()
print(soup.find("title"))

Output:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!