以下是使用Python的requests库设置HTTP代理IP的示例代码:
```python
import requests
proxy = {
'http': 'http://your_proxy_ip:your_proxy_port',
'https': 'http://your_proxy_ip:your_proxy_port'
}
response = requests.get('Example Domain', proxies=proxy)
print(response.text)
```
其中,`your_proxy_ip`和`your_proxy_port`分别为你的HTTP代理IP和端口号。将其替换为你自己的代理IP和端口号即可。如果你的代理IP需要用户名和密码认证,可以在`proxy`字典中添加`'http': 'http://username:password@your_proxy_ip:your_proxy_port'`和`'https': 'http://username:password@your_proxy_ip:your_proxy_port'`两个键值对,将`username`和`password`替换为你的代理用户名和密码。
#! -*- encoding:utf-8 -*-import requests# 要访问的目标页面targetUrl = "http://ip.hahado.cn/ip"# 代理服务器proxyHost = "ip.hahado.cn"proxyPort = "39010"# 代理隧道验证信息proxyUser = "username"proxyPass = "password"proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {"host" : proxyHost,"port" : proxyPort,"user" : proxyUser,"pass" : proxyPass,}proxies = {"http" : proxyMeta,"https" : proxyMeta,}resp = requests.get(targetUrl, proxies=proxies)print resp.status_codeprint resp.text