Open In App

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

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:






# 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:




# 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:


Article Tags :