Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pjialin/pyproxy-async

基于 Python Asyncio + Redis 实现的代理池
https://github.com/pjialin/pyproxy-async

async proxy proxy-pool redis

Last synced: about 2 months ago
JSON representation

基于 Python Asyncio + Redis 实现的代理池

Awesome Lists containing this project

README

        

# PyProxy-Async
基于 Python 协程 + Redis 实现的简单的代理池维护,及代理 IP 抓取服务

## 流程图
![流程图](https://doc.pjialin.com/stuff/B6LkuGaXEMtItuPtT69CFQ.png)

## Features
* HTTP/HTTPS 检测
* 协程实现
* Web Api 接口支持

## TODO
- [x] Docker Support
- [x] Custom check rule Support
- [x] TSDB Support (Prometheus has been supported)
- [ ] More api Support

## Usage
**环境依赖 Python 3.6 +**
1. 克隆
```
git clone https://github.com/pjialin/pyproxy-async
cd pyproxy-async
```
2. 安装依赖
```
pip install -r requirements.txt
```

3. 完善配置文件
```
cp config.toml.example config.toml
```

4. 启动
```
python main.py
```
### Docker 使用
1. 拉取镜像
```
docker pull pjialin/pyproxy-async:latest
```

2. 下载配置文件
```
curl -o config.toml https://raw.githubusercontent.com/pjialin/pyproxy-async/master/config.toml.example
```

3. 启动
```
docker run -d -v $(PWD)/config.toml:/code/config.toml -v pyproxy-data:/code/data --name pyproxy pjialin/pyproxy-async:latest
```

## Web Api
启动完成之后,访问 `127.0.0.1:8080/get_ip` (配置文件中的端口),即可获得一个随机的 IP, 如
```
# curl http://127.0.0.1:8080/get_ip
{"ip":"213.6.45.18","port":"39252","http":"http://213.6.45.18:39252"}

# 支持过滤条件 https,rule 如
curl http://127.0.0.1:8080/get_ip?https=1&rule=google
```

### 从文件或 Url 中加载已存在的 IP 列表
**文件**
1. 将文件命名为 `*.ip.txt`,如 `new.ip.txt`,并放在根目录下,文件格式为 `host:port`,如
```
127.0.0.1:80
127.0.0.1:8080
```

2. 加载到 IP 池中
```
python load.py [file_name] # 默认加载所有 *.ip.txt 文件
```
**从 Url 中加载**
```
python load.py url # 如 python load.py https://ser.com/ip 支持任意文本,程序通过正则进行匹配
```

### 添加抓取服务
增加新的 IP 抓取服务非常简单,只需要定义好要抓取的页面和对应的解析器,框架会自动加载并进行抓取。
在 `src/sites` 目录中提供了一个示例文件,[site.py.example](https://github.com/pjialin/pyproxy-async/blob/master/src/sites/site.py.example),供参考

### 集群支持
目前支持使用同一个 Redis 地址,实现集群 IP 检测以及抓取

## License
[Apache License 2.0](https://github.com/pjialin/pyproxy-async/blob/master/LICENSE)