如何通过API获取代理IP(Python)
发布时间: 2022-05-31 09:38:02
阅读量: 1090 人次
相关API
代码中所涉及的API可在【API接入指南】中查看。
参考代码
def getProxy(): try: # 提取用API api_url = "https://api.sshttp.cn/getIp" # 实例ID - 后台可查 app_key ='000000000000000000' # 实例密码 - 后台可查 app_secret ='xxxxxxxx' # 获取代理IP res = requests.get(api_url, params={'appKey': app_key, 'appSecret': app_secret, 'wt': 'text', 'cnt': 1}) proxy_ip = str(res.content, 'utf-8').split('\r\n') # 打印代理IP print(proxy_ip) except ConnectionError: print('拒绝连接')