Sunday, November 17, 2024
Google search engine
HomeLanguagesFind the title tags from a given html document using BeautifulSoup in...

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:

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:

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments