以下是一个使用HTTP隧道代理的示例代码模板:
```python
import requests
def send_request(url, proxy_host, proxy_port):
# 设置代理
proxies = {
'http': f'http://{proxy_host}:{proxy_port}',
'https': f'http://{proxy_host}:{proxy_port}'
}
try:
# 发送请求
response = requests.get(url, proxies=proxies)
# 处理响应
if response.status_code == 200:
print(response.text)
else:
print(f'Request failed with status code: {response.status_code}')
except requests.exceptions.RequestException as e:
print(f'Request failed: {e}')
# 设置代理服务器的地址和端口
proxy_host = '127.0.0.1'
proxy_port = '8080'
# 设置目标网址
url = 'Example Domain'
# 发送请求
send_request(url, proxy_host, proxy_port)
```
请注意,这只是一个示例代码模板,你需要根据你自己的实际情况进行修改和适配。
#! -*- 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_code
print resp.text
标签:HTTP,示例,host,proxy,Linux,print,http,proxies,port
From: https://blog.51cto.com/u_15822686/6590594