|
1 | 1 | import requests |
2 | 2 |
|
3 | 3 | # TODO: Add more status code functionality. |
| 4 | + |
| 5 | + |
4 | 6 | def check_url(url): |
5 | | - ''' |
6 | | - This function uses status codes to check various states of any website. |
7 | | - ''' |
| 7 | + # This function uses status codes to check various states of any website. |
| 8 | + |
8 | 9 | r=requests.get(url) |
9 | | - if r.status_code==200: |
| 10 | + if r.status_code == 200: |
10 | 11 | return "Website is online." |
11 | | - elif r.status_code==301: |
| 12 | + elif r.status_code == 300: |
| 13 | + return "Website has different choices and cannot be resolved into one" |
| 14 | + elif r.status_code == 301: |
12 | 15 | return "Website has been redirected permanently." |
13 | | - elif r.status_code==404: |
14 | | - return "Website not found!" |
| 16 | + elif r.status_code == 302: |
| 17 | + return "Website has been redirected temporarily" |
| 18 | + elif r.status_code == 400: |
| 19 | + return "The request could not be understood by the server due to malformed syntax" |
| 20 | + elif r.status_code == 401: |
| 21 | + return "The request requires user authentication" |
| 22 | + elif r.status_code == 403: |
| 23 | + return "Forbidden. The server understood the request, but is refusing to fulfill it" |
| 24 | + elif r.status_code == 404: |
| 25 | + return "Website not found!" |
| 26 | + elif r.status_code == 503: |
| 27 | + return "The web server is unable to handle your HTTP request at the time" |
15 | 28 |
|
16 | | -url=input("Please enter a website, inclusive of 'http://' > ") |
17 | | -print check_url(url) |
| 29 | +url = input("Please enter a website, inclusive of 'http://' > ") |
| 30 | +print(check_url(url)) |
0 commit comments