Plain Text
复制代码1
#! -*- encoding:utf-8 -*-
2
3
import requests
4
import random
5
6
# 要访问的目标页面
7
targetUrl = "http://httpbin.org/ip"
8
9
# 要访问的目标HTTPS页面
10
# targetUrl = "https://httpbin.org/ip"
11
12
# 代理服务器(产品官网 www.16yun.cn)
13
proxyHost = "t.16yun.cn"
14
proxyPort = "31111"
15
16
# 代理验证信息
17
proxyUser = "username"
18
proxyPass = "password"
19
20
proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {
21
"host" : proxyHost,
22
"port" : proxyPort,
23
"user" : proxyUser,
24
"pass" : proxyPass,
25
}
26
27
# 设置 http和https访问都是用HTTP代理
28
proxies = {
29
"http" : proxyMeta,
30
"https" : proxyMeta,
31
}
32
33
34
# 设置IP切换头
35
tunnel = random.randint(1,10000)
36
headers = {"Proxy-Tunnel": str(tunnel)}
37
38
39
40
resp = requests.get(targetUrl, proxies=proxies, headers=headers)
41
42
print resp.status_code
43
print resp.text
若有收获,就点个赞吧