Python 완전 식별 인증 코드 자동 로그 인 실례 상세 설명

1.직접 코드 붙 이기

#!C:/Python27
#coding=utf-8
 
 
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from pytesser import *
from PIL import Image,ImageEnhance,ImageFilter
from selenium.common.exceptions import NoSuchElementException,TimeoutException
import os,time
 
 
 
 
def before():
 
 
  driver.get(src)
 
 
  time.sleep(1)
 
 
  driver.maximize_window() #        
 
 
  print ('
...') def Convertimg(): imglocation = ("//*[@id='loginForm']/div[4]/div[2]/img[1]") # driver.save_screenshot('E:\\pythonScript\\Codeimages\\code.png') # im = Image.open('E:\\pythonScript\\Codeimages\\code.png') left = driver.find_element_by_xpath(imglocation).location['x'] top = driver.find_element_by_xpath(imglocation).location['y'] right = driver.find_element_by_xpath(imglocation).location['x'] + driver.find_element_by_xpath(imglocation).size['width'] bottom = driver.find_element_by_xpath(imglocation).location['y'] + driver.find_element_by_xpath(imglocation).size['height'] im = im.crop((left, top, right, bottom)) im.save('E:\\pythonScript\\Codeimages\\screenshot.png') print u"
" # os.remove('E:\\pythonScript\\Codeimages\\code.png') print u"
" # src = ('E:\\pythonScript\\Codeimages\\screenshot.png') # Cutedge(src) # os.remove('E:\\pythonScript\\Codeimages\\screenshot.png') # im = Image.open('E:\\pythonScript\\Codeimages\\CutedgeImage.png') imgry = im.convert('L') # threshold = 100 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1) out = imgry.point(table, '1') out.save('E:\\pythonScript\\Codeimages\\rgb.png') #vcode = pytesseract.image_to_string(out) #print (vcode) txtcode = image_to_string(out) print u"
:",image_to_string(out) print len(txtcode.strip()) print if len(txtcode.strip()) == 4: print u" " else: print u" , " driver.quit() # driver.find_element_by_id("username").send_keys("123456") driver.find_element_by_id("password").send_keys("123456") time.sleep(2) # driver.find_element_by_id("verifyCode").send_keys(txtcode.strip()) time.sleep(3) # driver.find_element_by_xpath("//*[@id='loginForm']/div[5]/div/img").click() #driver.find_element_by_class_name('loginbtn').click() time.sleep(7) # def Cutedge(src): # im = Image.open(src) w, h = im.size print u"
、 :",w,h box = (2,2,110,30) im.crop(box).save('E:\\pythonScript\\Codeimages\\CutedgeImage.png') print u"
CutedgeImage.png" # src = ("https://www.test.com") driver = webdriver.Chrome() #Firefox()# def method_2(src): before() # Convertimg() def clickInput(): driver.find_element_by_id("inputButton").click() print "
Input Click Finish" def clickOutput(): print u"
" # inputButton driver.find_element_by_id("outputButton").click() time.sleep(2) print (u'
, 10 ...') for i in range(1,4): ISOTIMEFORMAT="%Y-%m-%d %X" strTime = time.strftime( ISOTIMEFORMAT, time.localtime()) driver.refresh() print u"
",i," ...",strTime time.sleep(5) driver.find_element_by_id("outputButton").click() time.sleep(30) print # print u"
..." driver.refresh() print (u'
9 ...') time.sleep(505) print u"
",i,u" ,",u" ",i*10,u" " print (u'
...At The End OF,'+strTime) driver.quit() def isPass(): try: #driver.find_element_by_id("username").is_displayed() == True driver.find_element_by_id('status').text == (u" !") print (u"
**** _ ****") driver.quit() print (u"
, ...") except Exception: print (u"
**** _ ****") clickOutput() #------ click Output method_2(src) # isPass() #clickInput() #------ click Input #clickOutput() #------ click Output for i in range(1,6): driver = webdriver.Chrome() src = ("https://www.test.com") method_2(src) isPass() #clickOutput()
2.콘 솔 로그

        ...
 
          : 
 
         
 
        
 
      、    : 113 34
 
        CutedgeImage.png
 
         : gnbn
 
 
 
      ,       10   ...
 
      1  ... 2017-05-25 18:10:24
 
       ...
 
       9   ...
이상 의 Python 완전 식별 인증 코드 자동 로그 인 사례 에 대한 상세 한 설명 은 바로 편집장 이 여러분 에 게 공유 한 모든 내용 입 니 다.여러분 께 참고 가 되 고 저 희 를 많이 사랑 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기