我需要一些关于 Python 脚本的建议。我还是新手,自己学的。我在谷歌上找到了脚本。重新输入后,它不会在控制台中打印结果。脚本的结果如何显示在控制台中?详情如下:
C:\Python27>test1.py af8978b1797b72acfff9595a5a2a373ec3d9106d
C:\Python27>
按回车后,什么也没有发生。结果应该显示还是不显示?
这是我重新输入的代码:
#!/usr/bin/python
#coding: ascii
import requests
import sys
import re
url = 'http://hashtoolkit.com/reverse-hash?hash='
try:
hash = sys.argv[1]
except:
print ("usage: python "+sys.argv[0]+" hash")
sys.exit()
http = request.get(url+hash)
content = http.content
cracked = re.findall("<span title=\*decrypted (md5|sha1|sha384|sha512) hash\*>(.*)</span>", content) # expression regular
print ("\n\tAlgoritmo: "+cracked[0][0])
print ("\tPassword Cracked: "+cracked[0][1])
最佳答案
脚本的第一行称为 Shebang line
.
Shebang 行告诉脚本从该位置运行 Python 解释器。
您提供的 shebang 行是 Linux 系统路径,但从您执行 Python 的路径来看,您正在 Windows 上运行。
您可以在此处执行以下两项操作之一来解决此问题:
- Remove the first line from your script.
- Execute the script using
python test1.py COMMAND_LINE_ARGUMENTS
Change the first line of your script from
!/usr/bin/python
to#!python
(This is assuming that python is in your systemsPATH
variable.)`Execute the script using
test1.py COMMAND_LINE_ARGUMENTS
此外,您正在尝试导入
requests
未安装在标准库中的模块。如果您还没有安装它,您可以通过转到您的 Python 安装目录并转到
scripts
来安装它。文件夹。保持
shift
并右键单击并转到Open command window here
输入
pip install requests
然后按回车。之后你 应该 一切顺利,通过导航到脚本执行脚本并输入
test.py COMMAND_LINE_ARGUMENT
如果 Python 脚本没有
shebang line
:python test.py COMMAND_LINE_ARGUMENT
关于Python脚本不在命令提示符下打印输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47227301/