Last modified: Jan 10, 2023 By Alexander Williams

How to Build a Broken Link Checker Tool in Python

In this article, we are going to write a simple checker link tool.


  • requests

Before starting, we need to install the requests library.

Installation via pip:

pip install requests

Checker link tool

import requests

def link_checker(link):
        #GET request
        req = requests.get(link)

        #check status-code
        if req.status_code in [400,404,403,408,409,501,502,503]:
            return(f"{link} => Broken status-code:{req.status_code}")
            return(f"{link} => Good")
    except requests.exceptions.RequestException as e:
        # print link with Errs
        raise SystemExit(f"{link}: Somthing wrong \nErr: {e}")

Let me explain step by step.

  1. Send a get request for URL
  2. Check the status code of the request
  3. If the status code is in the list of all HTTP error codes, return...
  4. If not, return...



Output: => Good


Output: => Broken status-code:404

Check multiple links:

links = (

for link in links:
    c = link_checker(link)

Output: => Good => Good => Good, => Broken status-code:404

Finally, this is just a simple tool to understand how it works.

I hope this article helps you.