DEV Community

Free Python Code
Free Python Code

Posted on • Edited on

A simple Python script to check for broken links

🙂🖐

In this post, I will share with you how to make A simple Python script to check for broken links.

You can use it on your website to check for broken links.

In this post I will test this script on my API 🤗


import requests

bad_links = []

def check_link(link):
    res = requests.get(link)
    if res.status_code == 200:
        print('working')
    else:
        print('not working')
        bad_links.append(link)

links = [
    'http://127.0.0.1:8000/',
    'http://127.0.0.1:8000/test1',
    'http://127.0.0.1:8000/test2'
]


for link in links:
    check_link(link)


Enter fullscreen mode Exit fullscreen mode

result

working
not working
not working
Enter fullscreen mode Exit fullscreen mode

Now we're done 🤗

Don't forget to like and follow 🙂

Support me on PayPal 🤗
https://www.paypal.com/paypalme/amr396

Top comments (0)