from PIL import Image
from PIL import ImageEnhance
from pytesser import *
from requests import Session
from StringIO import StringIO
s = Session() # this session will hold the cookies
# here we first login and get our session cookie
s.post("https://w...content-available-to-author-only...o.uk?login",{"username":"username","password":"password"})
# now we're logged in and can request any page
resp = s.get("https://w...content-available-to-author-only...o.uk/levels/extras/captcha1.php")
i = Image.open(StringIO(resp.content))
i.save('captcha1.php.png')
#opens image and resizes it
im = Image.open("captcha1.php.png")
nx, ny = im.size
im2 = im.resize((int(nx*5), int(ny*5)), Image.BICUBIC)
im2.save("temp2.png")
#opens resized image and reads text
image = Image.open('temp2.png')
answer = image_to_string(image)
reverse = answer[::-1]
print reverse
s.post("https://w...content-available-to-author-only...o.uk/levels/captcha/1", {"answer":reverse})
ZnJvbSBQSUwgaW1wb3J0IEltYWdlCmZyb20gUElMIGltcG9ydCBJbWFnZUVuaGFuY2UKZnJvbSBweXRlc3NlciBpbXBvcnQgKgpmcm9tIHJlcXVlc3RzIGltcG9ydCBTZXNzaW9uCmZyb20gU3RyaW5nSU8gaW1wb3J0IFN0cmluZ0lPCgpzID0gU2Vzc2lvbigpICMgdGhpcyBzZXNzaW9uIHdpbGwgaG9sZCB0aGUgY29va2llcwoKIyBoZXJlIHdlIGZpcnN0IGxvZ2luIGFuZCBnZXQgb3VyIHNlc3Npb24gY29va2llCnMucG9zdCgiaHR0cHM6Ly93Li4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5vLnVrP2xvZ2luIix7InVzZXJuYW1lIjoidXNlcm5hbWUiLCJwYXNzd29yZCI6InBhc3N3b3JkIn0pCgojIG5vdyB3ZSdyZSBsb2dnZWQgaW4gYW5kIGNhbiByZXF1ZXN0IGFueSBwYWdlCnJlc3AgPSBzLmdldCgiaHR0cHM6Ly93Li4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5vLnVrL2xldmVscy9leHRyYXMvY2FwdGNoYTEucGhwIikKCmkgPSBJbWFnZS5vcGVuKFN0c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