# very simple website status checker
import requests
from requests import Response
# Response: this will give us back a response object
# which will contain all the necessary information regarding
# the website.
def get_response(url: str) -> Response:
return requests.get(url)
def show_response_info(response: Response) -> None:
print("Status:", response.status_code)
print("OK:", response.ok)
print("Links:", response.links)
print("Encoding:", response.encoding)
print("Is redirect:", response.is_redirect)
print("Is permanent redirect:", response.is_permanent_redirect)
def main() -> None:
website: str = "https://www.indently.io"
response: Response = get_response(website)
show_response_info(response)
print("-----")
website: str = "https://www.indently.io/abc"
response: Response = get_response(website)
show_response_info(response)
main()
# 결과
Status: 200
OK: True
Links: {}
Encoding: ISO-8859-1
Is redirect: False
Is permanent redirect: False
-----
Status: 404
OK: False
Links: {}
Encoding: iso-8859-1
Is redirect: False
Is permanent redirect: False
댓글 영역