
1、aiohtp是基于asyncio模块的异步HTTP客户端/服务端框架。
2、如果不需要保留请求的对话状态,请求将通过aiohttp进行.request直接发送回复。
3、aiohttp使用字典、list传输参数或通过传输字符串直接传输参数。
实例
importtime
importasyncio
importaiohttp
asyncdefget_html():
asyncwithaiohttp.request('GET',"https://open.163.com/")asres:
returnawaitres.text()
asyncdefmain():
tasks=[asyncio.ensure_future(get_html())foriinrange(20)]
dones,pendings=awaitasyncio.wait(tasks)
fortaskindones:
print(len(task.result()))
if__name__='__main__':
start_time=time.perf_counter()
asyncio.run(main())
print("aiohttp异步采集消耗时间为:",time.perf_counter()-start_time)
#aiohttp异步采集消耗时间为0.275251032
以上就是python中aiohttp库的理解,希望对大家有所帮助。更多Python学习指导:python基础教程