验证码截图接打码平台
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