proxy_pool
CLAUDE.md24k starsChanged 5 months agoMITView on GitHub
本文件为 Claude Code (claude.ai/code) 在本仓库中工作时提供指导。
- Installs packages
Files
CLAUDE.md
本文件为 Claude Code (claude.ai/code) 在本仓库中工作时提供指导。
技术栈
Python (3.8–3.11)、Flask (API)、Redis/SSDB (存储)、APScheduler (调度)。依赖版本固定记录在 requirements.txt 中。
常用命令
- 安装依赖:
pip install -r requirements.txt - 运行代理爬取/验证调度器:
python proxyPool.py schedule - 运行 API 服务器:
python proxyPool.py server - 查看启用的代理源:
python proxyPool.py fetcher - 运行单元测试:
pytest tests/unit/ - 运行 API 测试:
pytest tests/api/ - 运行集成测试(需真实 Redis):
pytest tests/integration/ -m integration - 运行全部测试:
pytest - 查看覆盖率:
pytest --cov=. --cov-report=term-missing
测试
目录结构
tests/
├── conftest.py # 共享 fixtures(app、client、fake_redis、proxy_obj、reset_singleton)
├── unit/ # 纯逻辑,零外部依赖
│ ├── test_proxy.py # Proxy 类:构造、序列化、setter、add_source
│ ├── test_db_client.py # DbClient.parseDbConn URI 解析
│ ├── test_config.py # ConfigHandler 环境变量覆盖
│ ├── test_validator.py # formatValidator 正则匹配
│ ├── test_base_fetcher.py # BaseFetcher 基类解析方法
│ └── test_fetcher_sources.py # 各代理源 fetcher yield 逻辑
├── api/ # Flask 测试客户端,mock ProxyHandler
│ └── test_proxy_api.py # /get /pop /all /count /delete 全路由
└── integration/ # 需要真实 Redis,标记 @pytest.mark.integration
├── test_redis_client.py # RedisClient 完整 CRUD
└── test_ssdb_client.py # SsdbClient 完整 CRUD测试分层
- unit/:不依赖外部服务,用
unittest.mock或fakeredis模拟,CI 必跑 - api/:使用 Flask
app.test_client(),mock 掉ProxyHandler,不依赖数据库 - integration/:需要真实 Redis,通过
@pytest.mark.integration标记,按需执行
测试依赖
pytest、pytest-cov、fakeredis(纯 Python Redis 模拟,无需真实服务)
关键约定
- 测试函数命名:
test_前缀 + 下划线命名(test_get_with_https) - 每个测试前自动重置
Singleton._inst,避免单例泄漏 - 集成测试与单元测试共存:单元测试用 fakeredis 跑,集成测试标记后按需执行
高层架构
免费代理池项目,爬取公开代理源、验证代理可用性、持久化存储到 Redis/SSDB,并通过 Flask RESTful API 提供代理服务。
核心组件
- 爬取器 (
fetcher/):插件架构。baseFetcher.py定义BaseFetcher基类(提供parseProxiesFromText/yieldUniqueProxies共享方法,约定name/url/enabled属性和fetch()方法)。每个代理源在sources/目录下独立文件,继承BaseFetcher。调度器自动扫描目录加载enabled=True的源。setting.py的PROXY_FETCHER_EXCLUDE黑名单可临时禁用指定源。 - 数据库层 (
db/):抽象dbClient接口,包含 Redis (redisClient.py) 和 SSDB (ssdbClient.py) 两种实现。通过setting.py中的DB_CONN配置连接(格式:redis://:pwd@ip:port/db或ssdb://:pwd@ip:port)。 - 调度器 (
helper/scheduler.py):基于 APScheduler 的定时任务,驱动爬取器运行并触发验证。时区通过setting.py中的TIMEZONE配置。 - 验证器 (
helper/validator.py):使用HTTP_URL(http://httpbin.org) 和HTTPS_URL(https://www.qq.com) 测试代理,超时时间由VERIFY_TIMEOUT指定(默认 10 秒)。超过MAX_FAIL_COUNT的代理会被移除。当代理池数量低于POOL_SIZE_MIN(默认 20)时触发重新爬取。 - API (
api/proxyApi.py):Flask 接口,包含以下端点:/get:随机获取一个代理(?type=https可筛选 HTTPS 代理)/pop:获取并删除一个代理/all:列出所有代理/count:代理数量统计/delete:通过?proxy=host:port删除指定代理- 服务运行在
HOST:PORT(默认0.0.0.0:5010),配置来自setting.py。
- 命令行入口 (
proxyPool.py):基于 click 的命令行工具,包含schedule和server两个子命令。
扩展代理源
- 在
fetcher/sources/目录下新建.py文件,继承BaseFetcher,声明name/url/enabled属性,实现fetch()方法 yield 出host:port字符串。 - 调度器下一轮采集自动发现并启用,无需修改配置。可用
python proxyPool.py fetcher查看启用列表。
关键配置
所有运行时配置均在 setting.py 中:
HOST/PORT:API 绑定的地址和端口DB_CONN:数据库连接字符串PROXY_FETCHER_EXCLUDE:爬取器黑名单(自动扫描enabled=True的源,排除黑名单中的)HTTP_URL/HTTPS_URL:验证目标 URLVERIFY_TIMEOUT:验证超时时间(默认 10 秒)MAX_FAIL_COUNT:代理被移除前允许的最大失败次数POOL_SIZE_MIN:触发重新爬取的最小代理池数量阈值PROXY_REGION:是否启用代理地区属性(默认True)TIMEZONE:调度器时区(默认Asia/Shanghai)
代码风格与命名规范
- 文件头:每个
.py文件必须包含以下标准头部:# -*- coding: utf-8 -*- """ ------------------------------------------------- File Name: fileName.py Description : 文件功能描述 Author : JHao date: yyyy/mm/dd ------------------------------------------------- Change Activity: yyyy/mm/dd: 修改内容简述 (修改时添加此行) ------------------------------------------------- """ __author__ = 'JHao' - 缩进:4 个空格(Python 标准)
- 文件命名:驼峰命名,如
proxyFetcher.py、dbClient.py、redisClient.py、webRequest.py - 类命名:帕斯卡命名,如
ProxyFetcher、RedisClient、SsdbClient、ProxyValidator - 方法命名:混合风格——数据库/爬取器方法使用驼峰命名(
getAll、getCount、changeTable、parseProxiesFromText),属性和辅助方法使用下划线命名(user_agent、fail_count、check_count) - 爬取器文件:小写命名(如
zdaye.py、kuaidaili.py),类名 PascalCase(如ZdayeFetcher、KuaidailiFetcher) - 常量(在
setting.py中):大写下划线命名(DB_CONN、PROXY_FETCHER_EXCLUDE、HTTP_URL、MAX_FAIL_COUNT) - 变量:下划线命名(
proxy_obj、proxy_str、https) - 注释/文档字符串:源文件头部和行内注释通常使用中文(普通话)
- 单例模式:使用自定义
Singleton元类(util/singleton.py)结合six.withMetaclass实现
注意事项
- 运行测试前需先安装测试依赖:
pip install pytest pytest-cov fakeredis - 单元测试和 API 测试不依赖外部服务,可直接运行;集成测试需启动 Redis
Trending
Quiet this year.about the whole repository
Who's talking about jhao104/proxy_pool
- 521xueweihan/HelloGitHub“python爬虫代理IP池”GitHub · Aug 4, 2017 · 1 reactions
- ihmily/ip-info-api“如题”GitHub · Apr 15, 2025
- AsaChiri/DDRecorder“如果可以,希望后续可以增加内置 proxypool 的版本 绕过风控”GitHub · Dec 17, 2022
- chroblert/JCRandomProxy“更新proxy_pool接口参数”GitHub · Apr 11, 2022
- DIYgod/RSSHub“添加动态代理池的支持”GitHub · Jul 2, 2021
The biggest 5 of 19 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 19
Talked about on GitHub and the web (19 times).
On GitHub · 13
- Aug 4, 2017python爬虫代理IP池 — 521xueweihan/HelloGitHub1 reaction · 1 comment
- Apr 15, 2025如题 — ihmily/ip-info-api0 reactions
- Dec 17, 2022如果可以,希望后续可以增加内置 proxypool 的版本 绕过风控 — AsaChiri/DDRecorder0 reactions · 2 comments
- Apr 11, 2022更新proxy_pool接口参数 — chroblert/JCRandomProxy0 reactions
- Jul 2, 2021添加动态代理池的支持 — DIYgod/RSSHub0 reactions · 3 comments
8 more on GitHub
- Apr 24, 2020proxy_pool: need socks proxies — jm33-m0/mec0 reactions · 3 comments
- Feb 4, 2020关于代理,我发现了这个项目,不知有没有用 — kajweb/wqxuetang_downloader0 reactions · 2 comments
- Jan 22, 2020ip proxy — lsq/officetools0 reactions
- Dec 18, 2019:pushpin: 自动切换代理ip — testerSunshine/123060 reactions · 1 comment
- Jun 3, 20192019-6-3备份书签 — xx-zhang/googlebookmarks2md0 reactions
- Nov 14, 2017支持SSDB数据库吗? — awolfly9/IPProxyTool0 reactions · 1 comment
- Nov 13, 2017A list of prev trials — franklingu/proxypool0 reactions · 2 comments
- Nov 7, 2017抓取大量免费代理 ip,提取有效 ip 使用 — XX-net/XX-Net0 reactions · 2 comments
On the web · 6
- Apr 7, 2022ProxyPool 爬虫代理IP池(分享)_spider-flow ... — google.com
- Feb 15, 2022爬虫福音:Github星标14K+,一个开源的IP代理池 — google.com
- Jul 10, 2020GitHub: ProxyPool 爬虫代理IP池原创 — blog.csdn.net
- Jul 10, 2020GitHub: ProxyPool 爬虫代理IP 池 — google.com
- Aug 20, 2019大神好,针对反爬能力较强的网站,我们的IP代理池效果怎么 ... — google.com
1 more on the web
- Aug 4, 2019有没有大神愿意详细说一下这个代理池怎么配置使用的#317 — google.com
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

