動態驗證碼處理UI自動化獲取處理

解決思路兩種:
1.直接linux catalina.out讀取:一分每10s輪詢出現新的直接讀取返回<br>
2.緩存注入cookie,先手動登陸獲取session 而後經過注入user,pwd 進cookielinux

 





import paramiko import os from time import sleep class SSH(object): def __init__(self,host,port,user,pwd): self.host=host self.port=port self.user=user self.pwd=pwd """此方法是統計在登錄以前獲取的服務日誌code的數量""" def before_count(self,logfile_absolute_path): logfile_parentdir,logfile_name=os.path.split(logfile_absolute_path) shell="cd {}; cat {}|grep 動態驗證碼爲".format(logfile_parentdir,logfile_name) ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(self.host,self.port,self.user,self.pwd) self.ssh=ssh stdin, stdout, stderr = self.ssh.exec_command(shell) res,err = stdout.readlines(),stderr.readlines() result = res if res else err return len(result) # """其實這樣寫不是最好辦法,解決多行根本是paramiko執行機制, # 每次執行完ssh.exec_command()函數會自動回到session初始化root路徑,多行建議以;分號隔開""" def ssh_connect(self,logfile_absolute_path,beforecode_number): target_code="" for i in range(6): logfile_parentdir,logfile_name=os.path.split(logfile_absolute_path) shell="cd {}; cat {}|grep 動態驗證碼爲".format(logfile_parentdir,logfile_name) ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(self.host,self.port,self.user,self.pwd) self.ssh=ssh stdin, stdout, stderr = self.ssh.exec_command(shell) res,err = stdout.readlines(),stderr.readlines() result = res if res else err if len(result)> beforecode_number: var=result[-1].strip() a=var.split("-")[-1] target_code=a.split(r":")[-1].strip() break else: sleep(10) self.ssh.close() return target_code

  

cookie注入:見我csdn直接能夠跑代碼本身觀察效果郵箱手動登陸是有滑塊攔截的shell

https://blog.csdn.net/chen498858336/article/details/83795911緩存

相關文章
相關標籤/搜索