diff --git a/cmts_scraper.py b/cmts_scraper.py index f753da5..ab444b3 100644 --- a/cmts_scraper.py +++ b/cmts_scraper.py @@ -372,6 +372,11 @@ async def fetch_raw_config(host: str, username: str, password: str, config_type: await process.stdin.drain() # 簡單清理頭尾的雜訊 (例如指令本身的 echo) + # 1. 清除 ANSI 控制碼 (如顏色、游標移動) 與退格鍵 \x08 + cleaned_output = re.sub(r'\x1b\[[0-9;]*[a-zA-Z]|\x08', '', raw_output) + # 2. 清除殘留的 --More-- 文字 + cleaned_output = re.sub(r'--More--', '', cleaned_output) + lines = raw_output.splitlines() clean_lines = [line for line in lines if not line.startswith(cmd) and not line.startswith("admin@")] return "\n".join(clean_lines).strip()