码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-01-08 14:21:38      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:识别   selenium   ast   空格   sharp   new   pytho   就是   hot   

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)

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

标签:识别   selenium   ast   空格   sharp   new   pytho   就是   hot   

原文地址:https://www.cnblogs.com/1996-88/p/12166142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!