如何利用python+Selenium对登录的验证码进行验证?


python+Selenium自动识别验证码
Fg.save_screenshot('D:\HuaYu\image\image.png')
ce = Fg.find_element_by_id("ensure") # 具体的id要用F12自行查看
print(ce.location)
im = Image.open('D:\HuaYu\image\image.png') 根据图片调整位置
img = im.crop((860,507,945,532))
print(img)
img.save('D:\HuaYu\image\image01.png') # 这里就是截取到的验证码图片
image2=Image.open('D:\HuaYu\image\image01.png')
sharp_img=ImageEnhance.Contrast(image2).enhance(2.0)#将图片二进制化
sharp_img.save('D:\HuaYu\image\image02.png')#形成新的图片
sleep(1)
codeText=pytesseract.image_to_string(Image.open('D:\HuaYu\image\image02.png').convert('L'))
print(codeText)
newcode=codeText.replace(" ", '')#去掉图片中多余的空格
Fg.find_element_by_name('code').send_keys(newcode)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM