关于代理池


代理池的维护

https://cuiqingcai.com/7048.html

代理IP池项目

https://github.com/jhao104/proxy_pool
https://github.com/henson/proxypool
https://github.com/Python3WebSpider/ProxyPool
https://www.89ip.cn/tqdl.html?num=9999

代理池+ssr

https://www.cnblogs.com/websec80/articles/14470193.html

代理池工具

ProxyPool

安装

Docker方式

docker-compose up

使用

查看代理数量

http://192.168.3.203:5555/count

获取随机一个代理地址

http://localhost:5555/random

获取所有

http://192.168.3.203:5555/all

扩展代理爬虫

from pyquery import PyQuery as pq
from proxypool.schemas.proxy import Proxy
from proxypool.crawlers.base import BaseCrawler

BASE_URL = 'http://www.664ip.cn/{page}.html'
MAX_PAGE = 5

class Daili66Crawler(BaseCrawler):
    """
    daili66 crawler, http://www.66ip.cn/1.html
    """
    urls = [BASE_URL.format(page=page) for page in range(1, MAX_PAGE + 1)]
    
    def parse(self, html):
        """
        parse html file to get proxies
        :return:
        """
        doc = pq(html)
        trs = doc('.containerbox table tr:gt(0)').items()
        for tr in trs:
            host = tr.find('td:nth-child(1)').text()
            port = int(tr.find('td:nth-child(2)').text())
            yield Proxy(host=host, port=port)

proxy_pool

Docker安装

docker pull jhao104/proxy_pool
docker run --env DB_CONN=redis://:password@ip:port/db -p 5010:5010 jhao104/proxy_pool:latest

本地安装

pip install -r requirements.txt
# 修改配置文件setting.py,知道redis密码,端口等
# 启动调度程序
python proxyPool.py schedule
# 启动webApi服务
python proxyPool.py server
# 也可直接运行start.sh文件,将python替换为python3即可使用python3启动

API

启动web服务后, 默认配置下会开启 http://127.0.0.1:5010 的api接口服务:

apimethodDescriptionparams
/GETapi介绍None
/getGET随机获取一个代理可选参数: ?type=https 过滤支持https的代理
/popGET获取并删除一个代理可选参数: ?type=https 过滤支持https的代理
/allGET获取所有代理可选参数: ?type=https 过滤支持https的代理
/countGET查看代理数量None
/deleteGET删除代理?proxy=host:ip

使用代理池

import requests

def get_proxy():
    return requests.get("http://127.0.0.1:5010/get/").json()

def delete_proxy(proxy):
    requests.get("http://127.0.0.1:5010/delete/?proxy={}".format(proxy))

# your spider code

def getHtml():
    # ....
    retry_count = 5
    proxy = get_proxy().get("proxy")
    while retry_count > 0:
        try:
            html = requests.get('http://www.example.com', proxies={"http": "http://{}".format(proxy)})
            # 使用代理访问
            return html
        except Exception:
            retry_count -= 1
    # 删除代理池中代理
    delete_proxy(proxy)
    return None

Scylla

https://github.com/imWildCat/scylla

安装

Docker方式

docker pull wildcat/scylla
docker run -d -p 8899:8899 -p 8081:8081 -v /var/www/scylla:/var/www/scylla --name scylla wildcat/scylla:latest
#或
docker run -d -p 8899:8899 -p 8081:8081 --name scylla wildcat/scylla

pip方式

pip install scylla
scylla --help
scylla# 运行爬虫和 Web 服务器

源码方式

git clone https://github.com/imWildCat/scylla.git
cd scylla

pip install -r requirements.txt

npm install# 或 yarn installmake build-assets

python -m scylla

JSON API

代理 IP 列表

http://localhost:8899/api/v1/proxies

可选 URL 参数:

参数默认值说明
page1页码
limit20每页显示代理 IP 的数量
anonymousany是否显示匿名代理。可选值:true,只显示匿名代理;false,只显示透明代理。
httpsany是否显示 HTTPS 代理。可选值:true,只显示 HTTPS 代理;false,只显示 HTTP 代理。
countries只选取特定国家的代理,格式示例:US,或者多国家:US,GB

结果样例:

{
    "proxies": [{
        "id": 599,
        "ip": "91.229.222.163",
        "port": 53281,
        "is_valid": true,
        "created_at": 1527590947,
        "updated_at": 1527593751,
        "latency": 23.0,
        "stability": 0.1,
        "is_anonymous": true,
        "is_https": true,
        "attempts": 1,
        "https_attempts": 0,
        "location": "54.0451,-0.8053",
        "organization": "AS57099 Boundless Networks Limited",
        "region": "England",
        "country": "GB",
        "city": "Malton"
    }, {
        "id": 75,
        "ip": "75.151.213.85",
        "port": 8080,
        "is_valid": true,
        "created_at": 1527590676,
        "updated_at": 1527593702,
        "latency": 268.0,
        "stability": 0.3,
        "is_anonymous": true,
        "is_https": true,
        "attempts": 1,
        "https_attempts": 0,
        "location": "32.3706,-90.1755",
        "organization": "AS7922 Comcast Cable Communications, LLC",
        "region": "Mississippi",
        "country": "US",
        "city": "Jackson"
    },
    ...
    ],
    "count": 1025,
    "per_page": 20,
    "page": 1,
    "total_page": 52
}

系统统计

http://localhost:8899/api/v1/stats

结果样例:

{
    "median": 181.2566407083,
    "valid_count": 1780,
    "total_count": 9528,
    "mean": 174.3290085201
}

HTTP 正向代理服务器

默认情况下,Scylla 会在端口 8081 启动一个 HTTP 正向代理服务器(Forward Proxy Server)。 这个服务器会从数据库中选择一个刚更新过的代理,并将其用作正向代理。 每当发出 HTTP 请求时,代理服务器将随机选择一个代理。

注意:目前不支持 HTTPS 请求。

使用此代理服务器的 “curl” 示例如下:

curl http://api.ipify.org -x http://127.0.0.1:8081

你也可以在 requests 中使用这个特性:

requests.get('http://api.ipify.org', proxies={'http': 'http://127.0.0.1:8081'})

Web 界面

打开 http://localhost:8899 即可访问本项目的 Web 界面。

代理 IP 列表

http://localhost:8899/

声明:Hack All Sec的博客|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 关于代理池


Hacker perspective for security