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

8 Replies, 1477 Views

yo, if you're tired of setting up proxies manually, try `requests.Session()`. You can configure the proxies once and reuse the session. Like this:

```python
import requests

session = requests.Session()
session.proxies = {
'http': 'http://your-proxy-ip:port',
'https': 'http://your-proxy-ip:port'
}

response = session.get('http://example.com')
```

Saves a lot of hassle for python 环境使用代理. Also, for async, `httpx` is a good alternative to `aiohttp`.

Messages In This Thread



Users browsing this thread: 1 Guest(s)