-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestfy.py
38 lines (31 loc) · 1.03 KB
/
Testfy.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
33
34
35
36
37
38
# status code checker
import requests
import csv
import time
class Testfy:
SLEEP = 0 # Time in seconds the script should wait between requests
url_list = []
url_statuscodes = []
url_statuscodes.append(["url", "status_code"]) # set the file header for output
def getStatuscode(url):
try:
r = requests.head(url, verify=False, timeout=5) # it is faster to only request the header
return (r.status_code)
except:
return -1
# Url checks from file Input
# use one url per line that should be checked
with open('urls.csv', newline='') as f:
reader = csv.reader(f)
for row in reader:
url_list.append(row[0])
# Loop over full list
for url in url_list:
print(url)
check = [url, getStatuscode(url)]
time.sleep(SLEEP)
url_statuscodes.append(check)
# Save file
with open("urls_withStatusCode.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(url_statuscodes)