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

16 Replies, 997 Views

If you're looking for something lightweight, `urllib` works too, but `requests` is way cleaner IMO. Here's how you'd do it:

```python
from urllib.request import urlopen
from urllib.error import URLError

try:
urlopen("https://example.com", timeout=10)
print("Website is reachable.")
except URLError:
print("Website is down or unreachable.")
```

For scheduling, check out `schedule` library or just use cron jobs if you're on Linux.

Messages In This Thread



Users browsing this thread: 1 Guest(s)