Python req.text.find(“”==-1?

Python req.text.find(“”==-1?,python,brute-force,Python,Brute Force,我想知道代码的细节。 特别是,为什么req.text.find是-1和req.text[index:index+30] 好的,让我们看看这个 req = session1.post(URL, cookies=cookie, data=data1) # Makes a POST request. req now holds the response body if (req.text.find("Password Incorrect!") == -1): # Look for the text

我想知道代码的细节。 特别是,为什么req.text.find是-1和req.text[index:index+30]


好的,让我们看看这个

req = session1.post(URL, cookies=cookie, data=data1)  # Makes a POST request. req now holds the response body
if (req.text.find("Password Incorrect!") == -1):  # Look for the text "Password Incorrect!" in the text of the response body
因此,在python中,有两种方法可以查找字符串中特定子字符串的索引:str.indexsubstr和str.findsubstr。在这两种情况下,如果substr出现在str中,那么这些函数将返回substr开始的str中的索引。它们之间的区别在于,如果substr未出现在str中,则index将引发一个索引器,而find将返回-1

因此,当我们检查req.text.findPassword是否不正确时!==-1,我们正在检查子字符串密码是否不正确!不出现在req.text中


您是否编写了此代码,如果是,您应该知道它的功能。python查找和字符串切片很容易在documentationWhy reg.text[index:index+30]…?你想知道什么?这句话会导致一些你意想不到的结果吗?你想知道语法吗?
req = session1.post(URL, cookies=cookie, data=data1)  # Makes a POST request. req now holds the response body
if (req.text.find("Password Incorrect!") == -1):  # Look for the text "Password Incorrect!" in the text of the response body
if (req.text.find("Password Incorrect!") == -1):  # continuing on...
    index = req.text.find("Authkey")              # Find the index of the string "AuthKey" in req.text
    print("\n\n")
    print(req.text[index:index+30])               # print the contents of `req.text` from that index
    print("\n\n")                                 #   through the next 30 characters
    input("Press Any KEY to exit.......")         # and finally, exit
    exit(0)
else:
    print("Wrong Num :" + str(i))                 # If we DO find "Password Incorrect!" in req.text,
                                                  #   then we just say "Wrong Number" and continue on with the loop.