概述:
本文介绍了一个基于Python的简单目录扫描工具,它可以自动检索网页源代码中的关键字,并将结果保存到指定的文件中。通过使用Python的requests库,该工具提供了一种高效、灵活的方法,可用于网络安全测试和网站管理等领域。
这次,我在1.0版本中进行了一个升级,感觉1.0太麻烦了,每次都要进入到代码中去修改字典,修改输出的文件名,关键字啊什么的,这次使用命令行就可以更改了!
import argparse
import requests
def httpContext(file_name, keyword, output_file):
with open(file_name, 'r', encoding='utf-8') as good_file:
for line in good_file:
url = line.strip() # 去除行末尾的换行符
response = requests.get(url) # 发送请求
contents = response.text.lower() # 获取响应的源代码并转换为小写
if keyword in contents:
with open(output_file, 'a', encoding='utf-8') as output:
output.write(url + '\n')
def main(args):
url = args.url # 目标 URL
dir_file = args.dir_file # 存储目录的文件名