Python-webdriver Identification Login Verification code
There's nothing to say directly on the code!
#-*-coding:utf-8-*-#Time:2017/9/29 7:16#Author:yangyangjunImport Time fromPytesseractImport* fromSeleniumImportWebdriver fromPILImportImage, ImageenhanceImportBaseinfourl=Baseinfo.urldriver=Webdriver. Firefox () Driver.maximize_window () driver.get (URL) time.sleep (3) Driver.save_screenshot ('Verifycode.png')#intercept the current page, which has the verification code we needTime.sleep (2)#Location Verification CodeImgElement = Driver.find_element_by_xpath (".//*[@id = ' imgobj ')")#Get verification code x, y axis coordinatesLocation =imgelement.location#get the length and width of the verification codeSize =imgelement.sizedriver.quit ()#as the position coordinates we need to intercept.Rangle = (int (location['x']), int (location['y']), int (location['x']+size['width']), int (location['y']+size['Height']))#Openi = Image.open ('Verifycode.png')#use the crop function of image to intercept the area we need againImgry=i.crop (Rangle)#use the crop function of image to intercept the area we need againImgry.save ('Getverifycode.png') im=image.open ('Getverifycode.png') im= Im.convert ('L')#image enhancement, binary valuesharpness=imageenhance.contrast (IM)#Contrast Enhancementsharp_img= Sharpness.enhance (2.0) Sharp_img.save ("Newverifycode.png") newverify= Image.open ('Newverifycode.png')#using image_to_string to identify verification codesText=image_to_string (newverify). Strip ()#using image_to_string to identify verification codes#Text1 = image_to_string (' newverifycode.png '). Strip ()Printtext#Print Text1
Python-webdriver Identification Login Verification code