-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_check.py
33 lines (29 loc) · 934 Bytes
/
url_check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import click
import requests
import pandas as pd
import csv
@click.command()
@click.option('--csvfile', default='urls.csv', help='CSV file')
def get404s(csvfile):
"""Get list of urls returning a 404 error from a provided csv"""
df = pd.read_csv(csvfile)
resultFile = open("404s.csv", "wb")
wr = csv.writer(resultFile, dialect='excel')
for index, row in df.iterrows():
try:
r = requests.get(row['url'])
if r.status_code == 200:
wr.writerow([row['uuid'], row['url'], 'OK'])
else:
wr.writerow([row['uuid'], row['url'],str(r.status_code)])
except requests.exceptions.InvalidURL:
wr.writerow([row['uuid'], row['url'],'invalid URL'])
pass
except requests.exceptions.InvalidSchema:
wr.writerow([row['uuid'], row['url'], 'invalid URL'])
pass
except requests.exceptions.ConnectionError:
wr.writerow([row['uuid'], row['url'], 'connection error'])
pass
if __name__ == '__main__':
get404s()