class CheckingThread ( threading.Thread ):
def __init__ ( self, length ):
# length - the length of the strings being checked
threading.Thread.__init__ ( self )
self.length = length
def run ( self ):
ml = ('abcdefghijklmnopqrstuvwxyz')
stra = ""
self.genstr(stra, 0, self.length, ml, 0, self.isdir)
def isdir( self, patha ):
global fileh
path = "http://www.site.com/" + patha + "/"
site = urlopen(path).read()
if(site.startswith("<!DOCTYPE HTML PUBLIC \"-//W")):
print path + "\t\t => Exists"
fileh.write(path + "\n")
else:
print path + "\t\t => -"
def genstr( self, stra, k, n, a, count, fun ):
# Generates all possible strings of n length out of the given
# list of symbols (a) and passes each of them to function fun
#print a
if(k<n):
for i in a:
if(len(stra) == k):
stra += i
else:
stra = stra[:-1] + i
count = self.genstr(stra, k+1, n, a, count, fun)
return count
else:
fun(stra)
return count + 1
fileh = open("ahaha.txt", 'w')
for x in xrange ( 13 ):
z = x + 3
CheckingThread ( z ).start()
fileh.close()
Проверка сделана не очень продуманно, так как скрипт заточен под конкретный сайт.
Вопрос - почему так происходит и как с этим бороться?