赞
踩
- #! -*- encoding:utf-8 -*-
- import requests
- import random
- import requests.adapters
-
- # 要访问的目标页面
- targetUrlList = [
- "https://httpbin.org/ip",
- "https://httpbin.org/headers",
- "https://httpbin.org/user-agent",
- ]
-
- # 代理服务器(产品官网 www.16yun.cn)
- proxyHost = "t.16yun.cn"
- proxyPort = "31111"
-
- # 代理隧道验证信息
- proxyUser = "username"
- proxyPass = "password"
-
- proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {
- "host": proxyHost,
- "port": proxyPort,
- "user": proxyUser,
- "pass": proxyPass,
- }
-
- # 设置 http和https访问都是用HTTP代理
- proxies = {
- "http": proxyMeta,
- "https": proxyMeta,
- }
-
- # 访问三次网站,使用相同的Session(keep-alive),均能够保持相同的外网IP
- s = requests.session()
-
- # 设置cookie
- cookie_dict = {"JSESSION":"123456789"}
- cookies = requests.utils.cookiejar_from_dict(cookie_dict, cookiejar=None, overwrite=True)
- s.cookies = cookies
-
- for i in range(3):
- for url in targetUrlList:
- r = s.get(url, proxies=proxies)
- print r.text
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。