import requests
def check_website_status(url):
try:
response = requests.get(url)
if response.status_code == 200:
return "Website is up and running."
else:
return f"Website is down with status code {response.status_code}."
except requests.ConnectionError:
return "Could not connect to the website."
# Example usage:
url = "https://www.example.com"
status = check_website_status(url)
print(status)
Kịch bản này định nghĩa một hàm check_website_status
lấy URL làm đầu vào và trả về thông báo cho biết trang web đang hoạt động hay không. Bạn có thể thay thế "https://www.example.com"
với URL của trang web bạn muốn kiểm tra.
Bình luận (0)
Chưa có bình luận nào ở đây, bạn có thể là người đầu tiên!