python
...小于 1 分钟
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