Need a simple code to check a website in Python—any recommendations? or What’s the best code to check

16 Replies, 994 Views

Hey! For a quick code to check a website python script, I'd go with `requests`. It's super easy to use. Here's a basic snippet:

```python
import requests
try:
response = requests.get("https://example.com", timeout=5)
print("Site is up!" if response.status_code == 200 else "Site is down.")
except:
print("Couldn't connect.")
```

If you wanna run it periodically, just slap it in a loop with `time.sleep(60)` for checks every minute.

Messages In This Thread



Users browsing this thread: 1 Guest(s)