#!/usr/bin/env python#Coding=utf-8Tesseract_cmd='d:\\tesseract-ocr\\tesseract'Try: fromPILImportImageImportpytesseractImportUrllib2ImportUrllibImportCookielibImportReImportsubprocessImportSYSImportTempfileImportOSImportShlexImportJSONexceptImporterror:Print 'Module Import error, use PIP to install' RaiseSystemexit" "file directory and return to the directory" "defmkdir (path):#remove space between left and right sidesPath=Path.strip ()#remove tail \ SymbolPath=path.rstrip ("\\") if notos.path.exists (path): os.makedirs (path)returnPathdefget_yundapic ():" "Loading Cookies" "CJ=Cookielib. Cookiejar (); Opener=Urllib2.build_opener (urllib2. Httpcookieprocessor (CJ)) Opener.addheaders={('user-agent','mozilla/5.0 (Windows NT 6.3; WOW64; rv:47.0) gecko/20100101 firefox/47.0')} urllib2.install_opener (opener) Picurl='http://ykjcx.yundasys.com/zb1qBpg2.php'req1=Urllib2. Request (Picurl) operate=Opener.open (req1) data=Operate.read ()return(cj,data);defsave_pic (input_file_name,data):ifdata = =None:returnfile=open (Input_file_name,"WB") file.write (data) File.flush () file.close ()defTempnam (): Tmpfile= Tempfile. Namedtemporaryfile (prefix="Tess_") returnTmpfile.namedefCleanup (filename):Try: os.remove (filename)exceptOSError:Passdefrun_tesseract (Input_filename, output_filename_base): Command=[Tesseract_cmd, Input_filename, Output_filename_base] proc= subprocess. Popen (command,stderr=subprocess. Pipe,shell=True)return(Proc.wait (), Proc.stderr.read ())defimage_to_string (data): Output_file_name_base=Tempnam () input_file_name='%s.png'%Tempnam () output_file_name='%s.txt'%Output_file_name_baseTry: Save_pic (input_file_name,data) status, Error_string=run_tesseract (input_file_name,output_file_name_base)ifStatus:RaiseF=Open (output_file_name)Try: returnF.read (). Strip ()finally: F.close ()finally: Cleanup (input_file_name) Cleanup (output_file_name)defSave_data (cookies,vcode): forCkinchCookies:ifCk.name = ='Phpsessid': Cookies=Ck.value Saveurl=' Save cookies and verification code addresses'Values= {'Cookies': Cookies,'WebSiteID': 1,'Code': Vcode} postdate=Json.dumps (values) Req=Urllib2. Request (saveurl,postdate) Response=Urllib2.urlopen (req) page=Response.read ()returnpagedefMain (): while(True): Cj,input_file_stream=get_yundapic () Vcode=image_to_string (Input_file_stream)ifVcode! ="' andLen (vcode) = = 3: ifRe.match (R'[a-za-z]+$', Vcode):Print 'knowledge of the mistakes' Else: Try: Num=eval (vcode)PrintNumPrintSave_data (Cj,eval (Vcode)); except: Pass " "While (True): Cj,captcha,input_file_stream = Get_pic () Vcode = image_to_string (Input_file_stream) If Vcode! = "and Len (vcode) = = 4:if Re.match (r ' [a-za-z]+$ ', Vcode): Print (Save_data (cj,ca Ptcha,vcode)) Else:print ' knowledge of the mistakes '" " " "Cj,input_file_stream = get_yundapic () Vcode = image_to_string (input_file_stream) print Vcode" "if __name__=='__main__': Main ()
More like direct rough stickers, not to say, look at the code, copy is running
Python Verification Code identification