[Python Reptile instance learning articles] - 2, to get free IP Agent

[Python Reptile instance learning articles] - 2, to get free IP Agent

As often checks the IP address when using the reptiles, it is necessary to find a place to get IP proxy. After struggling to find, finally found a fairly decent quality while providing free proxy site API interface, the following is the API encapsulation process.

use tools

3.6 1.Python
2.requests library
3. Free Agent website

1, to obtain a free agent

The site offers free agent two, one is to provide a free agent, and the other is to provide a free agent (a maximum of 15).

import requests

def GetFreeProxy():
    # 获取一个免费代理
    url='https://www.freeip.top/api/proxy_ip'
    ip=list(range(1))
    try:
        res=requests.get(url=url,timeout=20)
        # 将返回数据进行json解析
        result = res.json()
        ip[0]=result['data']['ip']+':'+result['data']['port']
        return ip
    except Exception:
        print('获取代理ip失败!正在重试···')
        # 异常重调
        GetFreeProxy()
        return 0

2, get one free agent

def GetFreeProxyList(page=1,country='all',isp='None',rder_by='validated_at',order_rule='DESC'):
# 获取一个免费代理列表
#(以下参数是开发文档上提供的,但并未提供提交方法,就先放这里了)
# 参数名	        数据类型 必传	说明	    例子
# page	        int	    N	第几页	1
# country	    string	N	所属国	中国,美国
# isp	        string	N	ISP	    电信,阿里云
# order_by	    string	N	排序字段	speed:响应速度,validated_at:最新校验时间 created_at:存活时间
# order_rule	string	N	排序方向	DESC:降序 ASC:升序
    url='https://www.freeip.top/api/proxy_ips'
    try:
        res = requests.get(url=url,timeout=20)
        result = res.json()
        # 将返回数据进行json解析
        ip=list(range(int(result['data']['to'])))
        for i in range(int(result['data']['to'])):
            ip[i]=result['data']['data'][i]['ip'] + ':' + result['data']['data'][i]['port']
        return ip
    except Exception:
        print('获取代理ip列表失败!正在重试···')
        GetFreeProxyList()
        return 0

3, the results show

Get a free agent :
Get a free agent
obtaining a free agent :
Get a free agent
a small operation Yeah Run for Life program to share small surgery; currently include: Python reptile learning, learning computer vision, artificial intelligence, learning, Matlab algorithm learning, Andrews reverse learning, hacking technology learning, we are committed to providing mutual exchange of mutual learning platform for the sharing of computer enthusiasts. Scan code to receive the attention of Python reptile 2000G video tutorials and hacking video tutorial ~
Run it a small operation, small surgical procedures for sharing life; currently include: Python reptile learning, learning computer vision, artificial intelligence, learning, Matlab algorithm learning, Andrews reverse learning, learning hacking techniques, dedicated to computer enthusiasts provide mutual exchange of mutual learning sharing platform.  Scan code to receive the attention of Python reptile 2000G video tutorials and hacking video tutorial ~

Released three original articles · won praise 4 · Views 5414

Guess you like

Origin blog.csdn.net/qq_40528553/article/details/103949152