UI自動化關於圖片驗證碼識別的解決方法




def __save_screenshot(self):
self.driver.save_screenshot('full_snap.png')
self.page_snap_obj = Image.open('full_snap.png')
return self.page_snap_obj

def __request_re(self):
self.img = self.driver.find_element_by_xpath('//*[@id="verifyImg"]')
self.location = self.img.location
self.size = self.img.size
left = self.location['x']
top = self.location['y']
right = left + self.size['width']
bottom = top + self.size['height']
page = self.__save_screenshot()
image_obj = page.crop((left, top, right, bottom))
image_obj.save('code002.png')
  
  # 別人的接口圖片訓練識別
# url1 = 'http://47.106.210.173:19952/captcha/v3'
url = 'http://47.98.142.71:19952/captcha/v3'
image = open('code002.png', 'rb')
r = requests.post(url, image)
t = r.content.decode()
s = json.loads(t)
m = s['message']
print(m)
return m


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM