简体   繁体   中英

How to break out of these loops in Python

import urllib2
    def Aviable(requrl)
        testdata='***'
        testreq=urllib2.Request(requrl, testdata) 
        testresponse = urllib2.urlopen(testreq)
        test=testresponse.read()
        if "methodResponse" in test:
            print "dddd"
            return True
        else:
            print "ssss"
            return False

    def Exploit():
        url=open('url.txt','r')
        for requrl in url:   #the aaa loop
            if Aviable(requrl):
                fuser=open('username.txt','r')
                fpass=open('password.txt','r')
                for username in fuser:   #the bbb loop
                    if Flag==1:
                        break
                    for password in fpass:  #the ccc loop
                        if Flag==2:
                            break
                        reqdata='********'
                        req=urllib2.Request(requrl,reqdata)
                        result=urllib2.urlopen(req).read()
                        num=num+1
                        if "aaa" in result :
                            print "Got it !"
                            print "username :"+username+"password :"+password
                            Flag=1
                            break
                        elif num==11:
                            Flag==2
                        elif "aaa" and "405" in result:
                            continue


    if __name__=='__main__':
        Exploit()

Is there a way to make when Flag==2 break the ccc loop and goto the bbb loop? It always goes to the aaa loop.

I want to change url after traversal the username.txt and password.txt

You really do not need to set Flag to 2 to break out of the ccc loop . Flags are generally needed only when trying to break out of outer loops when inside inner loop , its a mechanism to signal the outer loop and they its time to break out of those outer loops.

Example -

elif num==11:
    break

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM