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

16 Replies, 1767 Views

For a more robust code to check a website python solution, try `httpx`. It’s like `requests` but async-ready and has better timeout handling.

```python
import httpx

async def check_site(url):
try:
async with httpx.AsyncClient() as client:
resp = await client.get(url, timeout=10)
print(resp.status_code)
except httpx.RequestError:
print("Site’s having a bad day.")
```

Great for checking multiple sites fast!

Messages In This Thread



Users browsing this thread: 1 Guest(s)