Skip to content

Instantly share code, notes, and snippets.

@supertask
Created June 28, 2019 02:54
Show Gist options
  • Save supertask/cc1658b6731239b71e332f3d4b473088 to your computer and use it in GitHub Desktop.
Save supertask/cc1658b6731239b71e332f3d4b473088 to your computer and use it in GitHub Desktop.
Checking status codes of URL paths
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Requirements:
# Command:
# python3
# Python library(pip):
# requests
# urllib3
# File: checking_urls.txt
# https://www.nicho.co.jp/
# https://www.nicho.co.jp/internship/
# .....
#
# How to install:
# $ pip3 install requests
# $ pip3 install urllib3
#
import sys
import requests
import urllib3
from urllib3.exceptions import InsecureRequestWarning
urllib3.disable_warnings(InsecureRequestWarning)
# Get URLs file path
if len(sys.argv) < 2:
print("python check_status.py <URLs file path>")
sys.exit(1)
urls_filepath = sys.argv[1]
with open(urls_filepath, 'r') as rf:
url_line = rf.readline().rstrip('\n')
while url_line:
res = requests.get(url_line, verify=False)
if res.status_code == requests.codes.ok:
print("OK")
else:
print("Error status: %s, URL: %s" % (res.status_code, url_line))
sys.exit(1)
url_line = rf.readline().rstrip('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment