Python Code to Check Website is Live Or Down

By using this python code we can check any website is accessible or not. (Python Code to Check is Website Live Or Down)

Code

import requests

def check_website_response(url):
    try:
        response = requests.get(url)
        # Check the response status code
        if response.status_code == 200:
            print("Website is accessible!")
        else:
            print(f"Website returned a non-200 status code: {response.status_code}")
    except requests.exceptions.RequestException as e:
        print("Error occurred while connecting to the website:", e)

# Example usage
url = input("Enter the website URL: ")
check_website_response(url)

Console

Enter the website URL: https://pythock.com
Website is accessible!

Leave a Comment

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

Scroll to Top