我发现这个python代码用于检查网站的漏洞。它工作正常,但我需要一些修改。这个脚本获取所有HTTP响应(可能是200、301、302和其他,但不是404)。但现在我只想抓取200个OK响应,而不是301或其他。我怎么做这个。这个脚本运行速度也很慢。有什么方法可以加快python中线程的脚本速度吗
# -*- coding: utf-8 -*-
#Follow Me For More If You Like It Give It A Star
import requests
def FindAll():
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
f=open('list.txt', 'r').read().split('\n')
o=open('fixed.txt', 'r').read().split('\n')
with open('result.txt', 'w') as result:
for line in f:
if line == "":
continue;
newline=line.split('/')
parent_url=newline[2]
for line in o:
if line == "":
continue;
final_url='http://' + parent_url + '/' + line
try:
r = requests.get(final_url,headers=headers,timeout=3)
r.raise_for_status()
except requests.exceptions.HTTPError:
continue;
except requests.exceptions.ConnectionError:
continue;
except requests.exceptions.Timeout:
continue;
else:
print('\033[92m' + 'Found->' + final_url)
result.write(final_url+"\n")
print('\033[94m'+'Just Started The Panel_FInder. Please Wait')
FindAll()
print("Program Finished, See The result.txt File For Ur Result")
提前感谢你的帮助
打印状态代码后,将显示响应代码。您可以通过使用if语句过滤掉其他状态代码来过滤掉它们
关于速度,您应该使用多线程功能。在函数的参数中有一个名为num的变量或其他变量,并将其设置为零。每次请求完成时,将0增加1。然后多线程执行该函数。如果您运行5个线程,它将运行快5倍。当您有num变量时,它将防止任何url跳过等
相关问题 更多 >
编程相关推荐