使用 Python 破解 PDF 文件 3
Cracking a PDF File using Python 3
我目前正在完成一项任务,该任务要求我创建一个脚本来破解 PDF 文件中的密码,我已经有一个包含密码的列表,当提示输入路径时我遇到了问题文件并遇到 Name not define 错误,请注意我是编码新手。
file = raw_input('Path: ')
wordlist = 'wordlist.txt'
word =open(wordlist, 'r')
allpass = word.readlines()
word.close()
for password in allpass:
password = password.strip()
print ("Testing password: "+password)
instance = dispatch('pdf.Application')
try:
instance.Workbooks.Open(file, False, True, None, password)
print ("Password Cracked: "+password)
break
except:
pass
当程序 运行 时,它会尝试列表中的第一个密码,然后继续崩溃。
python Comsec.py
Path: /home/hall/Desktop/comsec121/examAnswers.pdf
Testing password: 123456
Traceback (most recent call last):
File "Comsec.py", line 11, in <module>
instance = dispatch('pdf.Application')
NameError: name 'dispatch' is not defined
请原谅我在这个网站上的排版,我正在尽力帮助您理解我的问题!
提前致谢!
此错误意味着在您的 Python 脚本中没有名称为 dispatch
的对象或函数。如果你尝试过,你会得到同样的错误:
instance = this_is_a_function_that_has_not_been_defined('pdf.Application')
通常,此函数应在 Python 模块中定义。要访问它,在代码的顶部你应该有一些像这样的导入语句:
from aBeautifulModuleForPDFs import dispatch
该模块将为您提供缺少的 dispatch
功能。签入 Google,我建议您尝试使用模块 pywin32。安装它(运行 pip install pywin32
在终端中)并在代码开头添加此行:
from win32com.client import Dispatch as dispatch
我目前正在完成一项任务,该任务要求我创建一个脚本来破解 PDF 文件中的密码,我已经有一个包含密码的列表,当提示输入路径时我遇到了问题文件并遇到 Name not define 错误,请注意我是编码新手。
file = raw_input('Path: ') wordlist = 'wordlist.txt' word =open(wordlist, 'r') allpass = word.readlines() word.close() for password in allpass: password = password.strip() print ("Testing password: "+password) instance = dispatch('pdf.Application') try: instance.Workbooks.Open(file, False, True, None, password) print ("Password Cracked: "+password) break except: pass
当程序 运行 时,它会尝试列表中的第一个密码,然后继续崩溃。
python Comsec.py Path: /home/hall/Desktop/comsec121/examAnswers.pdf Testing password: 123456 Traceback (most recent call last): File "Comsec.py", line 11, in <module> instance = dispatch('pdf.Application') NameError: name 'dispatch' is not defined
请原谅我在这个网站上的排版,我正在尽力帮助您理解我的问题! 提前致谢!
此错误意味着在您的 Python 脚本中没有名称为 dispatch
的对象或函数。如果你尝试过,你会得到同样的错误:
instance = this_is_a_function_that_has_not_been_defined('pdf.Application')
通常,此函数应在 Python 模块中定义。要访问它,在代码的顶部你应该有一些像这样的导入语句:
from aBeautifulModuleForPDFs import dispatch
该模块将为您提供缺少的 dispatch
功能。签入 Google,我建议您尝试使用模块 pywin32。安装它(运行 pip install pywin32
在终端中)并在代码开头添加此行:
from win32com.client import Dispatch as dispatch