跳至主要內容

python

爱喝水的木子...小于 1 分钟pythonpython

async

import asyncio
import aiohttp

# 目标网站的URL列表
urls = ['http://yourwebsite.com' + str(i) for i in range(10000)]

# 异步获取函数
async def fetch(url, session):
    async with session.get(url) as response:
        return response.status

# 主函数
async def main():
    async with aiohttp.ClientSession() as session:
        tasks = [fetch(url, session) for url in urls]
        responses = await asyncio.gather(*tasks)
        for url, response in zip(urls, responses):
            print(f'URL: {url}, Status Code: {response.status}')

# 运行主函数
asyncio.run(main())
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v3.1.3