forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsite_status_checker.py
34 lines (30 loc) · 1.08 KB
/
website_status_checker.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
import urllib.request
def check_website_status():
prompt = "Enter the Website URL: "
while True:
url = str(input(prompt)) #prompt
if url.startswith('https://'):
pass
elif url.startswith('http://'):
pass
else:
url = 'https://' + url
try:
headers = {}
headers['User-Agent'] = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 \
(KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36")
req = urllib.request.Request(url, headers=headers)
page = urllib.request.urlopen(req)
code = str(page.getcode())
print('The website ' + url + ' has returned a ' + code + ' code')
break
except Exception as e:
print(str(e))
print("Make sure you are entering a valid URL")
try_again = input("Do you want to try again (y/n): ")
try_again = try_again.lower()
if try_again == 'y':
continue
else:
break
check_website_status()