In this article, we are going to learn how to check whether any website is running or it’s down with a simple Python script. We will use Python’s requests library for sending ‘get’ request and ‘smtplib’ library for sending email notification when the website is up.It means we don’t need to check every time. Our Python program will notify us via email when the site is running.
This script simply checks whether a website is up or not. If it is up then it will send an email about this, if it is down then it will keep checking and when the site will be up, it will send an email and terminate.
Go to command prompt and write this command:
pip install requests, smtplib
Below are the steps:
- Put the entire code into a try block, to handle the exception.
- Send a get request to the website we want.
- If website is not running, then we don’t get a response thus throwing an exception.
- Then in except block we just print that website is not running.
- If there is no exception thrown, then it means we got the response and website is running.
- Now Create SMTP session for login through gmail.
- Enter your correct gmail id and password.
- Send the mail and done.
Below is the implementation:
- Website Blocker Using Python
- Create a Website Alarm Using Python
- Python | Parse a website with regex and urllib
- Check if email address valid or not in Python
- Python program to extract Email-id from URL text file
- Extracting email addresses using regular expressions in Python
- Django Sign Up and login with confirmation Email | Python
- Reading Python File-Like Objects from C | Python
- Python | Merge Python key values to list
- Python | Convert list to Python array
- Important differences between Python 2.x and Python 3.x with examples
- Python | Index of Non-Zero elements in Python list
- Python | Sort Python Dictionaries by Key or Value
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : gjaiswal108