安装 $ pip install unrar 解压 from unrar import rarfile # 源码:https://github.com/matiasb/python-unrar # 下载UnRAR.dll https://www.rarlab.com/rar_add.htm # 配置UnRAR.dll位置 # 在系统变量里配置 # UNRAR_LIB_PATH = C:\Pro
安装
$ pip install unrar解压
from unrar import rarfile# 源码:https://github.com/matiasb/python-unrar
# 下载UnRAR.dll https://www.rarlab.com/rar_add.htm
# 配置UnRAR.dll位置
# 在系统变量里配置
# UNRAR_LIB_PATH = C:\Program Files (x86)\UnrarDLL\x64\UnRAR64.dll
filename = 'rar压缩包路径'
extract_path = '解压路径'
fp = rarfile.RarFile(filename)
for pwd in range(0, 10000):
# 左对齐,不足补0
pwd = "{0:0>4}".format(pwd)
try:
fp.extractall(pwd=pwd, path=extract_path)
print('Success:', pwd)
break
except Exception:
print(pwd)
pass