API概览
1、接口简介
对于提取代理,我们提供了API接口,方便开发者批量获取代理ip列表。接口返回数据的格式支持空格、br、\r\n、json四种格式。
所有接口支持HTTP或者HTTPS请求,部分接口采用GET方法,采用POST方法。
2、快速入门
2.1 生成API链接
对于代理提取API,您可以在线生成API链接,内置到您的程序中:
2.2 测试API链接
2.2.1 浏览器测试
您可以把生成的API链接直接在浏览器里打开,查看返回结果。例如,您直接点击如下api链接
2.2.2 命令行测试
如果您在linux系统下,可以通过curl命令请求API链接查看结果:
curl "http://www.shenjidaili.com/api/?
uuid=bfbc31d28ae34825979d85e60ed5a0d8&num=1&place=中国&repeat=1&format=1&position=1"
2.3 代码样例
代码样例 - API接口
本文档包含调用神鸡代理API的代码样例,供开发者参考。
代码样例使用说明
- 代码样例直接运行无法得到正确的结果,因为代码中的API链接是虚构的,您替换成自己真实的链接就可以正常运行了。
- 代码样例正常运行所需的运行环境和注意事项在样例末尾均有说明,使用前请仔细阅读。
Python
urllib2
#!/usr/bin/env python #-*- coding: utf-8 -*- """使用urllib2调用API接口 """ import urllib2 #api链接 api_url = "http://www.shenjidaili.com/api/? uuid=bfbc31d28ae34825979d85e60ed5a0d8&num=1&place=中国&repeat=1&format=1&position=1" req = urllib2.Request(api_url) r = urllib2.urlopen(req) print r.code #获取Reponse的返回码 print r.read() #获取API返回内容
使用提示
- 运行环境要求 python2.6 / 2.7
urllib
#!/usr/bin/env python # -*- coding: utf-8 -*- """使用urllib.request调用API接口(在python3中urllib2被改为urllib.request) """ import urllib.request #api链接 api_url = "http://www.shenjidaili.com/api/? uuid=bfbc31d28ae34825979d85e60ed5a0d8&num=1&place=中国&repeat=1&format=1&position=1" req = urllib.request.urlopen(api_url) print(req.code) # 获取Reponse的返回码 print(req.read().decode('utf-8')) # 获取API返回内容
使用提示
- 运行环境要求 python3.x
requests
#!/usr/bin/env python #-*- coding: utf-8 -*- """使用requests调用API接口 """ import requests #api链接 api_url = "http://www.shenjidaili.com/api/? uuid=bfbc31d28ae34825979d85e60ed5a0d8&num=1&place=中国&repeat=1&format=1&position=1" r = requests.get(api_url) print(r.status_code) #获取Reponse的返回码 if r.status_code == 200: print(r.content.decode('utf-8')) #获取API返回内容
使用提示
- 此样例支持 Python 2.6—2.7以及3.3—3.7
- requests不是python原生库,需要安装才能使用: pip install requests