在做 ui 自动化时,遇到的第一个问题肯定是 “如何识别随机验证码图片”?
此系统中验证码为个位数计算型,首先分析验证码格式 “a +(—*/) b=”,获取 code 通过运算符进行分隔 a、b,运算最后求值
def calculate_code(img_codes):
print("截取前:"+img_codes)
img_code=img_codes[0:3]
print("截取后:"+img_code)
if '*' in img_code:
zhi = int(img_code.split('*')[0]) * int(img_code.split('*')[1])
print("*:" + str(zhi))
elif '+' in img_code:
zhi = int(img_code.split('+')[0]) + int(img_code.split('+')[1])
print("+:" + str(zhi))
elif '-' in img_code:
zhi = int(img_code.split('-')[0]) - int(img_code.split('-')[1])
print("-:" + str(zhi))
elif '/' in img_code:
zhi = int(int(img_code.split('/')[0]) / int(img_code.split('/')[1]))
print("/:" + str(zhi))
return str(zhi)