Python-webdriver Identification Login Verification code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.