How to get Page Title of Webpage using Python

There are many ways to achieve this but the best one is to use libraries requests, bs4 and lxml. So let's install these libraries using pip. If you guys don't have pip installed them get it installed using sudo apt-get install python-pip.

sudo pip install requests
sudo pip install bs4
sudo pip install lxml

Now let's create our python file get_title.py

import requests
from bs4 import BeautifulSoup as bs

req = requests.get('https://dwij.net')
soup = bs(req.content, 'lxml')
print(soup.select_one('title').text)

Now run it.

python get_title.py

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.