如何利用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)
posted @ 2020-01-08 13:39  张小姐的技术博客  阅读(711)  评论(0编辑  收藏  举报