CSkin博客
标题: 小白分享 [打印本页]
作者: suger 时间: 2020-3-13 17:43
标题: 小白分享
#! -*- encoding:utf-8 -*-
import requests
import random
# 要访问的目标页面
targetUrl = "www.mkt.51job.com"
# 要访问的目标HTTPS页面
# targetUrl = "https://www.mkt.51job.com"
# 代理服务器(产品官网 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,
}
# 设置IP切换头
tunnel = random.randint(1,10000)
headers = {"Proxy-Tunnel": str(tunnel)}
resp = requests.get(targetUrl, proxies=proxies, headers=headers)
print resp.status_code
print resp.text
欢迎光临 CSkin博客 (http://bbs.cskin.net/) |
Powered by Discuz! X3.2 |