插件配置持久化:
- plugin_settings 表新增 config_json 字段,支持存储每个插件的自定义配置
- BaseCrawlerPlugin 新增 default_config 属性和 update_config 方法
- PluginSettingsRepository 新增 get_config / set_config 方法
- PluginService 新增 get_plugin_config 和 update_plugin_config
- api/routes/plugins.py 新增 GET /{id}/config 和 POST /{id}/config 接口
- 前端 Plugins.vue 增加配置编辑对话框,支持动态渲染数字/布尔/字符串类型配置
- ip3366 插件示例化:增加 max_pages 配置项,验证配置生效后会动态更新爬取 URL
任务队列持久化:
- 新建 validation_tasks 表:id, ip, port, protocol, status, result, response_time_ms, created_at, updated_at
- 新建 ValidationTaskRepository,提供 insert_batch / acquire_pending / complete_task / reset_processing 等方法
- ValidationQueue 重构:
- submit() 时把任务写入数据库并唤醒 Worker
- Worker 通过 acquire_pending 原子取任务并验证
- 验证完成后更新任务状态并入库有效代理
- 启动时自动恢复之前中断的 processing 任务为 pending
- 支持 drain() 等待所有 pending 完成
- 调度器验证流程同样自动持久化到任务表
其他适配:
- 更新 api/deps.py 和 api/lifespan.py,移除对已删除 settings_service 的残留引用
- 更新前端 pluginService.js 和 api/index.js 增加配置相关 API
57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
import re
|
|
from typing import List
|
|
from bs4 import BeautifulSoup
|
|
from core.plugin_system import ProxyRaw
|
|
from plugins.base import BaseHTTPPlugin
|
|
from core.log import logger
|
|
|
|
VALID_PROTOCOLS = ("http", "https", "socks4", "socks5")
|
|
|
|
|
|
class Ip3366Plugin(BaseHTTPPlugin):
|
|
name = "ip3366"
|
|
display_name = "IP3366"
|
|
description = "从 IP3366 网站爬取免费代理"
|
|
default_config = {"max_pages": 5}
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self._update_urls()
|
|
|
|
def _update_urls(self):
|
|
max_pages = self.config.get("max_pages", 5)
|
|
self.urls = [
|
|
f"http://www.ip3366.net/free/?stype=1&page={i}" for i in range(1, max_pages + 1)
|
|
] + [
|
|
f"http://www.ip3366.net/free/?stype=2&page={i}" for i in range(1, max_pages + 1)
|
|
]
|
|
|
|
async def crawl(self) -> List[ProxyRaw]:
|
|
results = []
|
|
for url in self.urls:
|
|
html = await self.fetch(url, timeout=15)
|
|
if not html:
|
|
continue
|
|
soup = BeautifulSoup(html, "lxml")
|
|
list_div = soup.find("div", id="list")
|
|
if not list_div:
|
|
continue
|
|
table = list_div.find("table")
|
|
if not table:
|
|
continue
|
|
|
|
for row in table.find_all("tr"):
|
|
tds = row.find_all("td")
|
|
if len(tds) >= 5:
|
|
ip = tds[0].get_text(strip=True)
|
|
port = tds[1].get_text(strip=True)
|
|
protocol = tds[4].get_text(strip=True).lower() if len(tds) > 4 else "http"
|
|
if protocol not in VALID_PROTOCOLS:
|
|
protocol = "http"
|
|
if re.match(r"^\d+\.\d+\.\d+\.\d+$", ip) and port.isdigit():
|
|
results.append(ProxyRaw(ip, int(port), protocol))
|
|
|
|
if results:
|
|
logger.info(f"{self.display_name} 解析完成,获得 {len(results)} 个潜在代理")
|
|
return results
|