- 非认证的代理
import requests
proxies = {"http":"http://proxy_ip:proxy_port"}
requests.get("http://example.org", proxies=proxies)
- 需要认证的代理
import requests
proxies = {"http":"http://username:password@proxy_ip:proxy_port"}
r = requests.get("http://www.example.com/", proxies=proxies)
print(r.content)
or
import requests
from requests.auth import HTTPProxyAuth
proxies = {"http":"http://username:password@proxy_ip:proxy_port"}
auth = HTTPProxyAuth("username", "password")
r = requests.get("http://www.example.com/", proxies=proxies)
print(r.content)
建议使用第二种认证方式,第一种认证方式的的账号密码中如果有特殊字符@的话,会导致无法被识别出来.