29 lines
609 B
Python
29 lines
609 B
Python
# -*- encoding:utf-8 -*-
|
|
|
|
'''
|
|
@Author : dingjiawen
|
|
@Date : 2023/12/6 16:57
|
|
@Usage : aiohttp库的使用
|
|
@Desc :
|
|
@参考:https://github.dev/Python3WebSpider/AsyncTest demo12
|
|
'''
|
|
|
|
import aiohttp
|
|
import asyncio
|
|
|
|
|
|
async def fetch(session, url):
|
|
async with session.get(url) as response:
|
|
return await response.text(), response.status
|
|
|
|
|
|
async def main():
|
|
async with aiohttp.ClientSession() as session:
|
|
html, status = await fetch(session, 'https://cuiqingcai.com')
|
|
print(f'html: {html[:100]}...')
|
|
print(f'status: {status}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|