用 python 复现如下 golang 代码:if currentStateUrl != htmlIndex = stringsIndexcurrentStateUrl html ampIndex = stringsIndexcurrentStateUrlhtmlIndex & unicodeIndex = stringsIndexcurrentStateUrl
你可以使用 Python 的字符串操作函数来复现上述 Go 代码。以下是一个可能的实现:
if currentState.Url != "":
htmlIndex = currentState.Url.find("html")
ampIndex = currentState.Url[htmlIndex:].find("&")
unicodeIndex = currentState.Url[htmlIndex:].find("\\u0026")
if ampIndex != -1 and (ampIndex < unicodeIndex or unicodeIndex == -1):
endIndex = htmlIndex + ampIndex
else:
endIndex = htmlIndex + unicodeIndex
match = currentState.Url[:endIndex]
monkey.VisitedUrlMap[match] += 1
# monkey.VisitedUrlMap[currentState.Url] += 1
这段代码使用 Python 字符串的 find 方法来获取子字符串的索引,然后根据索引计算 endIndex。最后,将 match 添加到 monkey.VisitedUrlMap 中,并递增对应的计数器。
请注意,这只是一个可能的实现,具体实现可能根据你的需求和代码结构有所不同
原文地址: https://www.cveoy.top/t/topic/iair 著作权归作者所有。请勿转载和采集!