-
Notifications
You must be signed in to change notification settings - Fork 2
/
ex22.py
37 lines (26 loc) · 979 Bytes
/
ex22.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import platform
import aiohttp
import asyncio
async def index(session):
url = 'https://python.org'
async with session.get(url) as response:
print("Status:", response.status)
print("Content-type:", response.headers['content-type'])
html = await response.text()
return f"Body: {html[:15]}..."
async def doc(session):
url = "https://www.python.org/doc/"
async with session.get(url) as response:
print("Status:", response.status)
print("Content-type:", response.headers['content-type'])
html = await response.text()
return f"Body: {html[:15]}..."
async def main():
async with aiohttp.ClientSession() as session:
result = await asyncio.gather(index(session), doc(session))
return result
if __name__ == "__main__":
if platform.system() == 'Windows':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
r = asyncio.run(main())
print(r)