Skip to content

Instantly share code, notes, and snippets.

@patelmilanun
Last active September 27, 2017 11:47
Show Gist options
  • Save patelmilanun/b6429136e4ff10444b6888726b1c1812 to your computer and use it in GitHub Desktop.
Save patelmilanun/b6429136e4ff10444b6888726b1c1812 to your computer and use it in GitHub Desktop.
#get dir from user and make the folders
import os
ans = input("Want to create dir? Press y for yes, n for no:")
if ans == 'y':
dir = input("Enter the dir:")
for i in range(65,91):
os.makedirs(dir + "\\" + chr(i))
for i in range(0,10):
os.makedirs(dir + "\\" + str(i))
else:
dir = input("Enter the dir:")
#Main procedure
while 1:
try:
#for requesting url
import requests
req = str(requests.get('http://result1.gtu.ac.in/').text)
#Searching captcha link
import re
re.search('CaptchaImage',req)
temp = re.search('CaptchaImage',req)
data = req[temp.start():]
temp = re.search('"',data)
data = data[0:temp.end()-1]
url = "http://result1.gtu.ac.in/" + data
#Looping the procedure
for i in range(0,1000):
#for download image
import urllib.request
urllib.request.urlretrieve(url, "CaptchaImage.jpg")
#for cutting image
from PIL import Image
im = Image.open("CaptchaImage.jpg")
if i==0:
im.show()
box1 = (0, 0, 40, 50)
box2 = (40, 0, 80, 50)
box3 = (75, 0, 115, 50)
box4 = (115, 0, 150, 50)
char = []
char.append(im.crop(box1))
char.append(im.crop(box2))
char.append(im.crop(box3))
char.append(im.crop(box4))
#saving image
if i==0:
full_captcha = input("Enter captcha shown in image:")
if any(c.islower() for c in full_captcha):
break
sub_captcha = []
sub_captcha.append(full_captcha[0])
sub_captcha.append(full_captcha[1])
sub_captcha.append(full_captcha[2])
sub_captcha.append(full_captcha[3])
#retriving last image name
import glob
import os
k=0
if i==0:
name = [0, 0, 0, 0]
for j in sub_captcha:
list = glob.glob(dir + '\\' + j + '\\' + "*")
if i==0:
try:
name[k] = (os.path.basename(max(list,key=os.path.getctime)))
name[k] = int(name[k].split(".")[0])
except:
name[k] = -1
char[k].save(dir + "\\" + j + "\\" + str(name[k] + i + 1) + ".png")
k+=1
#debuging only
print(i)
if any(c.islower() for c in full_captcha):
break
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment