Files
ProxyPool/plugins/speedx.py
2026-01-27 21:17:36 +08:00

79 lines
2.5 KiB
Python

import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from core.crawler import BasePlugin
from core.log import logger
import re
import asyncio
class SpeedXPlugin(BasePlugin):
def __init__(self):
super().__init__()
self.name = "SpeedX代理源"
self.urls = [
"https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/http.txt",
"https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/socks4.txt",
"https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/socks5.txt"
]
async def parse(self, html):
if not html:
return
lines = html.split('\n')
count = 0
for line in lines:
line = line.strip()
if not line:
continue
if ':' in line:
parts = line.split(':')
if len(parts) >= 2:
ip = parts[0].strip()
port = parts[1].strip()
# 验证IP地址格式
if not re.match(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$', ip):
continue
# 验证端口是数字
if not port.isdigit() or not (1 <= int(port) <= 65535):
continue
# 根据 URL 判断协议
protocol = 'http'
if 'socks5' in self.current_url:
protocol = 'socks5'
elif 'socks4' in self.current_url:
protocol = 'socks4'
yield ip, int(port), protocol
count += 1
if count > 0:
logger.info(f"{self.name} 解析完成,从 {self.current_url} 获得 {count} 个潜在代理")
if __name__ == "__main__":
async def test_plugin():
plugin = SpeedXPlugin()
print(f"========== 测试 {plugin.name} ==========")
print(f"目标URL数量: {len(plugin.urls)}")
print(f"开始抓取...\n")
proxies = await plugin.run()
print(f"\n========== 抓取结果 ==========")
print(f"总计获取 {len(proxies)} 个代理:")
print("-" * 60)
for idx, (ip, port, protocol) in enumerate(proxies, 1):
print(f"{idx:3d}. {ip:15s} : {str(port):5s} | {protocol}")
print("-" * 60)
print(f"完成!共 {len(proxies)} 个代理~")
asyncio.run(test_plugin())