rarf = rarfile.RarFile(rarname) passFile=open(passwdtxt_name) #读取你设定的密码文件 for line in passFile.readlines(): try: password = line.strip('\n') #要修改某些东西可以再这里加 rarf.extractall(path=".", pwd=password) print("密码:{}".format(password)) break except: print("又错了")
错误处理
如果报错
1 2 3 4 5 6 7 8
Traceback (most recent call last): File "1.py", line 1, in <module> from unrar import rarfile File "C:\Users\***\AppData\Roaming\Python\Python38\site-packages\unrar\rarfile.py", line 26, in <module> from unrar import unrarlib File "C:\Users\***\AppData\Roaming\Python\Python38\site-packages\unrar\unrarlib.py", line 57, in <module> raise LookupError("Couldn't find path to unrar library.") LookupError: Couldn't find path to unrar library.