Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check HTTP Status of a csv list of URLS
import urllib3
import os
import csv
rows = []
http=urllib3.PoolManager()
#load the csv list of URLs to check
with open('urls.csv', 'r') as input:
csv_reader = csv.reader(input)
for blog in csv_reader:
#check blogs in list for status
try:
#this get response will only retry a url 3 times, does not preload the site data, and records the status but does not load a redirect
resp = http.request('GET', blog[0], retries=3, preload_content=False, redirect=False)
line = [blog[0], resp.status]
rows.append(line)
resp.release_conn()
#if there's a domain not found error, it will be caught by this except
except:
line = [blog[0], "no connection"]
rows.append(line)
with open('urlStatus.csv', 'w') as output:
csv_writer = csv.writer(output)
csv_writer.writerows(rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.