博客:https://www.wd0g.com/
这是干什么的?
该工具是爬取ThinkPHP中开启调试模式后的日志文件
具体详情请访问:https://phpinfo.me/2016/09/09/1351.html
代码
import requests, time, os
# 检查日志文件是否存在
def check(domain):
for date in range(0,365):
ext = time.strftime("%Y_%m_%d",time.localtime(time.time()-(86400*date)))
url = "%s/Runtime/Logs/%s.log" %(domain,ext[2:])
response = requests.get(url)
if response.status_code == 200:
yield {'status':True,'ext':ext,'data':response.text}
else:
yield {'status':False,'ext':ext}
# 保持日志内容到指定目录下
def save(domain, ext, data):
domainPath = './%s' %domain
fileName = './%s/%s.log' %(domain,ext)
if os.path.exists(domainPath) is False:
os.mkdir(domainPath)
file = open(fileName,'a+',encoding='gb2312')
file.write(data)
file.close()
# 获取文件夹名称
def getDName(domain):
isHttps = domain.find('https://') != -1
haveGan = domain[-1] == '/'
if isHttps:
domain = domain[8:]
else:
domain = domain[7:]
if haveGan:
domain = domain[:-1]
return domain
# 开始运行
def run(domain):
for result in check(domain):
if result['status'] == True:
save(getDName(domain),result['ext'],result['data'])
print(result['status'],result['ext'])
run('http://www.onethink.cn/')
其它
可能一些小细节没做到位,大概就这样了撒
本文来自: 蜗蜗侠's Blog-关注网络安全 http://blog.icxun.cn/Tools/293.html