A simple Python script to check for broken links

PHOTO EMBED

Wed Nov 29 2023 15:30:22 GMT+0000 (Coordinated Universal Time)

Saved by @amramroo ##python #coding

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)
content_copyCOPY

https://dev.to/amr2018/a-simple-python-script-to-check-for-broken-links-1b35