Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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:



Last Updated : 15 Mar, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads