test_proxy_ip.py 631 B

12345678910111213141516171819202122232425262728
  1. import aiohttp
  2. import asyncio
  3. # 您提供的代理信息
  4. proxy = 'http://s8P7v8:mmVgdf@45.158.197.113:8000'
  5. async def fetch(session, url):
  6. # 使用代理
  7. async with session.get(url, proxy=proxy) as response:
  8. return await response.text()
  9. async def main():
  10. urls = [
  11. "https://api.ip.cc",
  12. "https://icanhazip.com"
  13. ]
  14. async with aiohttp.ClientSession() as session:
  15. tasks = [fetch(session, url) for url in urls]
  16. results = await asyncio.gather(*tasks)
  17. for result in results:
  18. print(result)
  19. print()
  20. # 运行异步主函数
  21. asyncio.run(main())