From 06462b19397f57d4bc8003883440c6f8fbb65ddc Mon Sep 17 00:00:00 2001 From: lijinmiao Date: Sat, 8 Apr 2023 21:46:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=BD=E9=87=8F=E5=88=A0=E9=99=A4=E5=B7=B2?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=92=8C=E8=A7=A3=E5=8E=8B=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/interaction/manager.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/interaction/manager.py b/modules/interaction/manager.py index 800cdfe..12778ec 100644 --- a/modules/interaction/manager.py +++ b/modules/interaction/manager.py @@ -14,6 +14,7 @@ from modules.interaction.extractor import TextExtractor from modules.interaction.persistence import DbPersistence from libs.web.url import urlsite +from utils.filedir import traverse from libs.logger import logger browser_protocols = ('http', 'https', 'ftp') @@ -118,9 +119,21 @@ def clear(): os.remove(CRAWL_METRIC_PATH) if os.path.exists(EXTRACT_METRIC_PATH): os.remove(EXTRACT_METRIC_PATH) + # TODO 无法删除RAR压缩包解压后的文件 + # 错误信息: + # [WinError 3] 系统找不到指定的路径。 # 文件确定存在,路径无空格和特殊字符,python3.5.4下判断不存在,python3.8.10判断存在!! + # [WinError 5] 拒绝访问。 if os.path.exists(DOWNLOADS): - shutil.rmtree(DOWNLOADS) - os.makedirs(DOWNLOADS) + try: + shutil.rmtree(DOWNLOADS) + except: + for filepath in traverse(DOWNLOADS): + try: + os.remove(filepath) + except Exception as e: + logger.error(e) + if not os.path.exists(DOWNLOADS): + os.makedirs(DOWNLOADS) # sqlite = Sqlite() sqlite.truncate([TABLES.CrawlStat.value, TABLES.Extractor.value, TABLES.Sensitives.value])