def solve_captcha_reedeem(self): br = self.br element = br.find_element_by_class_name("gc-captcha-image") location = element.location size = element.size im = Image.open(StringIO.StringIO(base64.decodestring(br.get_screenshot_as_base64()))) left,top,right,bottom = location['x'],location['y'],location['x']+size['width'],location['y']+size['height'] im = im.crop((left,top,right,bottom)) im.save("captcha_reedem.jpg") text = tesseract_ocr.text_for_filename("captcha_reedem.jpg") br.find_element_by_xpath("//input[@name='captchaInput']").send_keys(text)
def solve_captcha_login(self): br = self.br element = br.find_element_by_id('auth-captcha-image') # find part of the page you want image of location = element.location size = element.size im = Image.open(StringIO.StringIO(base64.decodestring(br.get_screenshot_as_base64()))) left = location['x'] top = location['y'] right = location['x'] + size['width'] bottom = location['y'] + size['height'] im = im.crop((left, top, right, bottom)) # defines crop points im.save("captcha.jpg") text = tesseract_ocr.text_for_filename("captcha.jpg") br.find_element_by_id("auth-captcha-guess").send_keys(text)
def test_text_for_filename(self): filename = os.path.join(self.test_dir, 'code.tiff') text = tesseract_ocr.text_for_filename(filename, 'eng') self.assertEqual(text, '0578')