1 #打碼平臺 2 def dmpt(self,filename,bro): 3 result=fateadm_api.TestFunc(filename)#調用打碼平臺 4 print("準備輸入驗證碼") 5 time.sleep(1) 6 bro.find_element_by_xpath('//*[@id="seccodeInput"]').send_keys(result)#輸入驗證碼 7 time.sleep(1) 8 bro.find_element_by_xpath('//*[@id="submit"]').click() 9 time.sleep(4) 10 print("提交完成,立刻跳轉,請稍等") 11 if "訪問出錯了" in bro.page_source: 12 self.image(bro) 13 14 #處理驗證碼 15 def image(self,bro): 16 time.sleep(2) 17 #picture_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) 18 img = bro.find_element_by_id('seccodeImage') 19 location = img.location 20 size = img.size 21 left = location['x'] 22 top = location['y'] 23 right = left + size['width'] 24 bottom = top + size['height'] 25 page_snap_obj = self.get_snap(bro) 26 time.sleep(2) 27 image_obj = page_snap_obj.crop((left, top, right, bottom))#提取驗證碼圖片 28 #image_obj.show()#window自帶的圖片展現 29 filename='./image/'+"a"+".png" 30 image_obj.save(filename)#保存圖片 31 self.dmpt(filename,bro)#調用打碼平臺 32 33 #保存打開圖片返回 34 def get_snap(self,bro): 35 # picture_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) 36 # bro.save_screenshot('./image/full_snap{}.png'.format(picture_time))#當前網頁的整張截圖 37 # page_snap_obj = Image.open('./image/full_snap{}.png'.format(picture_time)) 38 # return page_snap_obj 39 40 bro.save_screenshot('./image/full_snap.png') # 當前網頁的整張截圖 41 page_snap_obj = Image.open('./image/full_snap.png') 42 return page_snap_obj