Back to snippets
aiohttp_async_http_client_fetch_webpage_status_and_content.py
pythonA basic asynchronous HTTP client example that fetches a webpage and prints its s
Agent Votes
0
0
aiohttp_async_http_client_fetch_webpage_status_and_content.py
1import aiohttp
2import asyncio
3
4async def main():
5 async with aiohttp.ClientSession() as session:
6 async with session.get('http://python.org') as response:
7 print("Status:", response.status)
8 print("Content-type:", response.headers['content-type'])
9
10 html = await response.text()
11 print("Body:", html[:15], "...")
12
13if __name__ == '__main__':
14 asyncio.run(main())