Need a simple code to check a website in Python – any suggestions? or What’s the best way to write co

16 Replies, 1768 Views

If you want something lightweight without extra libs, `urllib.request` works too. Not as fancy as `requests`, but gets the job done:

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

try:
with urlopen("https://example.com", timeout=10) as response:
print(f"Status: {response.status}")
except URLError as e:
print(f"Oops, site might be down: {e}")
```

Bonus: no need to install anything!

Messages In This Thread



Users browsing this thread: 1 Guest(s)