知识点
代码演示(使用try 和except)
import argparse
import requests
import sys
def main():
parse = argparse.ArgumentParser(description="You can try : python dirst.py -u http://www.baidu.com -d dir.txt")
parse.add_argument('-u', '--uesr', dest='name', help='Please enter your url', type=str)
parse.add_argument('-d', '--dic', dest='diction', help='Please enter your dictionary', type=str)
args = parse.parse_args()
url = args.name
diction = args.diction
# 准备url和遍历字典
# url = "http://192.168.1.103:90"
try:
with open(diction, "r") as f:
for line in f.readlines():
line = line.strip()
# print(url+line)
# 让url加遍历的字典,如果遍历的的url中返回200就代表找到了目录,并打印出
r = requests.get(url + line)
if r.status_code == 200:
print("find it:" + r.url)
except:
print('Hello 主人!!! 很高兴见到你!')
print('让我来告诉你使用方法吧,嘻嘻嘻')
print('列如:python yc.py -u url -d dictionary 则为正确')
if __name__ == '__main__':
main()
代码演示(使用 try和except Exception)
import argparse
import requests
import sys
def main():
parse = argparse.ArgumentParser(description="You can try : python dirst.py -u http://www.baidu.com -d dir.txt")
parse.add_argument('-u', '--uesr', dest='name', help='Please enter your url', type=str)
parse.add_argument('-d', '--dic', dest='diction', help='Please enter your dictionary', type=str)
args = parse.parse_args()
url = args.name
diction = args.diction
# 准备url和遍历字典
# url = "http://192.168.1.103:90"
try:
with open(diction, "r") as f:
for line in f.readlines():
line = line.strip()
# print(url+line)
# 让url加遍历的字典,如果遍历的的url中返回200就代表找到了目录,并打印出
r = requests.get(url + line)
if r.status_code == 200:
print("find it:" + r.url)
except Exception as e:
print(str(e))
if __name__ == '__main__':
main()