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

16 Replies, 1004 Views

Pro tip: If you're checking multiple sites, `aiohttp` is a beast for async checks. Here's a tiny example:

```python
import aiohttp
import asyncio

async def check(url):
try:
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
print(f"{url} is up!" if resp.status == 200 else f"{url} is down.")
except:
print(f"{url} failed.")

asyncio.run(check("https://example.com"))
```

Might be overkill for one site, but scales like a champ.

Messages In This Thread



Users browsing this thread: 1 Guest(s)