如何在 Python 环境使用代理?有没有简单的方法?

8 Replies, 1266 Views

Hey! Great tip on using the `proxies` parameter in `requests`. For async stuff, you can totally use `aiohttp` with proxies too. Here's a quick example:

```python
import aiohttp
import asyncio

async def fetch():
proxies = 'http://your-proxy-ip:port'
async with aiohttp.ClientSession() as session:
async with session.get('http://example.com', proxy=proxies) as response:
return await response.text()

asyncio.run(fetch())
```

Also, check out [FreeProxy](https://freeproxy.io/) for free proxy lists if you're testing. Makes python 环境使用代理 way easier!

Messages In This Thread



Users browsing this thread: 1 Guest(s)