python_异常处理
生活随笔
收集整理的這篇文章主要介紹了
python_异常处理
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
知識(shí)點(diǎn)
代碼演示(使用try 和except)
import argparse import requests import sysdef 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.namediction = args.diction# 準(zhǔn)備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 sysdef 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.namediction = args.diction# 準(zhǔn)備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()總結(jié)
以上是生活随笔為你收集整理的python_异常处理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【复现】CVE-2015-1635-HT
- 下一篇: POC-EXP编写