Skip to content

Instantly share code, notes, and snippets.

@ajtulloch
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajtulloch/6fa88d68c1de4fd0bdd3 to your computer and use it in GitHub Desktop.
Save ajtulloch/6fa88d68c1de4fd0bdd3 to your computer and use it in GitHub Desktop.
from PIL import Image
import pyocr
import pyocr.builders
import re
def captcha(image, question):
tool = pyocr.get_available_tools()[0]
lang = tool.get_available_languages()[0]
img = Image.open(image).quantize(colors=6)
txt = tool.image_to_string(img, lang=lang, builder=pyocr.builders.TextBuilder())
return re.search(question, txt).group(1)
IMAGE = '/Users/tulloch/img.png'
PREFIX = "Please enter: (.*)"
print captcha(IMAGE, PREFIX)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment