Build Motivational Quote App in Python

Coder Singh
2 min readDec 28, 2022

Motivation is an essential part of life, and having access to a steady stream of uplifting and inspiring quotes can be a great way to stay motivated and focused. In this blog, we will look at how to create a Python application that fetches motivational quotes from the internet and displays them to the user.

The first step in building this application is to decide where you will get the quotes from. There are many websites that offer motivational quotes, and you can choose one that suits your needs. For this example, we will use the website “Brainy Quote” (https://www.brainyquote.com/).

To fetch the quotes from the website, we will use the Python library Beautiful Soup. Beautiful Soup is a popular library for web scraping and parsing HTML, and it makes it easy to extract data from websites. First, install Beautiful Soup by running the following command:

pip install beautifulsoup4

Next, create a new Python script and import the necessary libraries:

import requests from bs4 import BeautifulSoup

Then, use the requests library to fetch the HTML of the page that contains the quotes:

URL = "https://www.brainyquote.com/topics/motivational-quotes"
page = requests.get(URL)
soup = BeautifulSoup(page.text, 'html.parser')

Now, use Beautiful Soup to parse the HTML and extract the quotes. The exact method for doing this will depend on the structure of the HTML on the website you are using. Here is an example of how you might do it using Brainy Quote:

quotes = []
for quote in soup.find_all('a', class_='b-qt'):
quotes.append(quote.text)

Now that we have extracted the quotes from the website, we can display them to the user. There are many ways you could do this, but one simple way is to use the Python library random to choose a random quote from the list and print it to the console:

import random quote = random.choice(quotes) 
print(quote)

I hope this tutorial has been helpful and gives you a good starting point for creating your own motivational quote app with Python. Happy coding!

--

--