获取代理IP
# 流冠IP获取代理
# 提取订单
"""
orderId:提取订单号
secret:用户密钥
num:提取IP个数
pid:省份
cid:城市
type:请求类型,1=http/https,2=socks5
unbindTime:使用时长,秒/s为单位
noDuplicate:去重,0=不去重,1=去重
lineSeparator:分隔符
singleIp:切换,0=切换,1=不切换
"""
orderId = "O24032115183695757008"
secret = '9aa9e3cbaaf2493cb1fd1c61400565c8'
num = "1"
pid = "-1"
cid = ""
type = "1"
unbindTime = "600"
noDuplicate = "0"
lineSeparator = "0"
singleIp = "0"
timestam = str(int(time.time())) # 时间戳
# 计算sign
txt = "orderId=" + orderId + "&" + "secret=" + secret + "&" + "time=" + timestam
sign = hashlib.md5(txt.encode()).hexdigest()
# 访问URL获取IP
url = "http://api.hailiangip.com:8422/api/getIp?type=1" + "&num=" + num + "&pid=" + pid + "&unbindTime=" + unbindTime + "&cid=" + cid + "&orderId=" + orderId + "&time=" + timestam + "&sign=" + sign + "&dataType=0" + "&lineSeparator=" + lineSeparator + "&noDuplicate=" + noDuplicate + "&singleIp=" + singleIp
my_response = requests.get(url).content
js_res = json.loads(my_response)
def get_proxies(js_res):
for dic in js_res["data"]:
ip = dic["ip"]
port = dic["port"]
proxyUrl = "http://" + ip + ":" + str(port)
proxy = {'http': proxyUrl, "https": proxyUrl}
r = requests.get("http://www.baidu.com", proxies=proxy)
return str(ip) + ':' + str(port)
proxy = get_proxies(js_res)
proxies = {
"http": "http://%(proxy)s/" % {'proxy': proxy},
"https": "http://%(proxy)s/" % {'proxy': proxy}
}