打开 kookeey IP 代理平台,假如端口是 http://gate.kookeey.io:15959,账号: kookeey,密码: 12345678 )。
import urllib.request;
proxy = urllib.request.ProxyHandler({'https': 'http://kookeey:12345678@gate.kookeey.info:15959'})
opener = urllib.request.build_opener(proxy)
urllib.request.install_opener(opener)
content = urllib.request.urlopen('https://lumtest.com/myip.json').read();
print(content)# -*- coding: utf-8 -*-
import time
import base64
import requests
import hmac
import hashlib
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class KEKPROXY(object):
def __init__(self, accessid, token):
super(KEKPROXY, self).__init__()
self.session = requests.session()
self.accessid = accessid
self.token = token
def get_proxy(self):
ti = str(time.time())[:10]
# ti = ti.strip('.')
print((ti))
token_ = str(base64.b64encode(
(hmac.new(
bytes(self.token, encoding='utf-8'),
bytes('p=7450637&ts={}'.format(ti).strip('&'), encoding='utf-8'),
hashlib.sha1).hexdigest()).encode("utf-8")
),encoding="utf-8")
print(token_)
proxy = self.session.get('https://www.kookeey.com/ip?accessid={}&signature={}&p=7450637&ts={}'.format(self.accessid, token_, ti),verify=False).text
print(proxy)
def post_proxy(self):
ti = str(time.time())[:10]
# ti = ti.strip('.')
print((ti))
token_ = str(base64.b64encode(
(hmac.new(
bytes(self.token, encoding='utf-8'),
bytes('ts={}'.format(ti), encoding='utf-8'),
hashlib.sha1
).hexdigest()).encode("utf-8")
), encoding="utf-8")
headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
data = {
"lang": "en"
}
proxy = self.session.post(
'https://www.kookeey.com/clientapi/setlang?accessid={}&signature={}&ts={}'.format(self.accessid, token_, ti),
headers=headers,
data=data,
verify=False
).text
print(proxy)
if __name__ == '__main__':
accessid = "开发者ID"
token = "开发者token"
kek = KEKPROXY(accessid, token)
# kek.post_proxy() #post方法接口调用
kek.get_proxy() #get方法接口调用