如何使用SOCKS代理通过aiohttp发出请求?(How to use SOCKS proxies to make requests with aiohttp?)
import asyncio
import aiohttp
from aiosocksy.connector import ProxyConnector, ProxyClientRequest
async def fetch(url):
connector = ProxyConnector()
socks = 'socks5://127.0.0.1:12377'
async with aiohttp.ClientSession(connector=connector, request_class=ProxyClientRequest) as session:
async with session.get(url, proxy=socks) as response:
print(await response.text())
loop = asyncio.get_event_loop()
loop.run_until_complete(fetch('https://www.google.com'))

浙公网安备 33010602011771号