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)
Skrip ini mentakrifkan fungsi check_website_status
yang mengambil URL sebagai input dan mengembalikan mesej yang menunjukkan sama ada tapak web itu naik atau turun. Anda boleh menggantikan "https://www.example.com"
dengan URL tapak web yang ingin anda semak.
Komen (0)
Tiada ulasan di sini lagi, anda boleh menjadi yang pertama!