Esempio n. 1
0
def login():
    if os.path.isfile('cre.json'):
        with open('cre.json', 'r') as f:
            data = json.load(f)
            regno = data['username']
            passw = data['password']

    else:
        regno = raw_input("Registration Number: ")
        passw = raw_input("Password: "******"Fetching Captcha"
    r = br.open('https://vtop.vit.ac.in/student/stud_login.asp')
    html = r.read()
    soup = BeautifulSoup(html)
    im = soup.find('img', id='imgCaptcha')
    image_response = br.open_novisit(im['src'])
    img = Image.open(StringIO(image_response.read()))
    imgcpy = img.copy()
    starttime = timeit.default_timer()
    parser = CaptchaParser()
    captcha = parser.getCaptcha(img)
    stoptime = timeit.default_timer()

    print "Recognized Captcha:" + str(captcha) + " in " + str(stoptime -
                                                              starttime)
    formdata = {"regno": regno, "passwd": passw, "vrfcd": str(captcha)}
    data_encoded = urllib.urlencode(formdata)
    response = opener.open(
        'https://vtop.vit.ac.in/student/stud_login_submit.asp', data_encoded)

    print "Logging in User:"******"https://vtop.vit.ac.in/student/home.asp"):
        print "Success!"

    else:
        print '''Failed :(
                 Either Username or Password is wrong or there is some fault in decoding captcha try again'''

    return opener
def login():
    br = mechanize.Browser()
    br.set_handle_robots(False)
    br.set_handle_redirect(True)
    br.set_handle_referer(True)
    try:
        _create_unverified_https_context = ssl._create_unverified_context
    except AttributeError:
        pass
    else:
        ssl._create_default_https_context = _create_unverified_https_context
    cj = cookielib.CookieJar()
    br.set_cookiejar(cj)
    response = br.open('https://vtop.vit.ac.in/student/stud_login.asp')
    print 'Opened Login Form'
    html = response.read()
    soup = BeautifulSoup(html)
    im = soup.find('img', id='imgCaptcha')
    image_response = br.open_novisit(im['src'])
    img = Image.open(StringIO(image_response.read()))
    parser = CaptchaParser()
    captcha = parser.getCaptcha(img)
    br.select_form('stud_login')
    br.form['regno'] = REGNO
    br.form['passwd'] = PASSWORD
    br.form['vrfcd'] = str(captcha)
    print br.form
    print str(captcha) + ' Captcha Parsed'
    br.submit()
    print br
    print 'Submitted'
    if (br.geturl() == 'https://vtop.vit.ac.in/student/home.asp'):
        puts(colored.yellow("LOGIN SUCCESSFUL"))
        return br
    else:
        print 'Could not login'
        return None
Esempio n. 3
0
def login():
    br = mechanize.Browser()
    br.set_handle_redirect(True)
    br.set_handle_referer(True)
    cj = cookielib.CookieJar()
    br.set_cookiejar(cj)
    response = br.open('https://academics.vit.ac.in/student/stud_login.asp')
    html = response.read()
    soup = BeautifulSoup(html)
    im = soup.find('img', id='imgCaptcha')
    image_response = br.open_novisit(im['src'])
    img = Image.open(StringIO(image_response.read()))
    parser = CaptchaParser()
    captcha = parser.getCaptcha(img)
    br.select_form('stud_login')
    br.form['regno'] = REGNO
    br.form['passwd'] = PASSWORD
    br.form['vrfcd'] = str(captcha)
    br.submit()
    if (br.geturl() == 'https://academics.vit.ac.in/student/home.asp'):
        puts(colored.yellow("LOGIN SUCCESSFUL"))
        return br
    else:
        return None
Esempio n. 4
0
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

print "Fetching Captcha"

r = br.open('https://academics.vit.ac.in/parent/parent_login.asp')
html = r.read()
soup = BeautifulSoup(html)
im = soup.find('img', id='imgCaptcha')
image_response = br.open_novisit(im['src'])
img = Image.open(StringIO(image_response.read()))
imgcpy = img.copy()
starttime = timeit.default_timer()
parser = CaptchaParser()
captcha = parser.getCaptcha(img)
stoptime = timeit.default_timer()

print "Recognized Captcha:" + str(captcha) + " in " + str(stoptime - starttime)
br.select_form('parent_login')

regno = raw_input("Registration Number:")
dob = raw_input("Date of Birth:")

br.form['wdregno'] = regno
br.form['vrfcd'] = str(captcha)
br.form['wdpswd'] = dob

print "Logging in User:" + str(regno)
def login(reg_no="",pwd=""):

	#importing the required modules
	from bs4 import BeautifulSoup
	from CaptchaParser import CaptchaParser
	from PIL import Image
	import mechanize
	import os

    #handeling browser and browser initialisation
	br = mechanize.Browser()
	br.set_handle_robots(False)
	br.set_handle_equiv(True)
	br.set_handle_gzip(True)
	br.set_handle_redirect(True)
	br.set_handle_referer(True)

	#opening website
	response = br.open("https://vtop.vit.ac.in/student/stud_login.asp")
	#print br.geturl()

	#selecting the login form
	br.select_form("stud_login")

	#extracting captcha url
	soup = BeautifulSoup(response.get_data())
	img = soup.find('img', id='imgCaptcha')
	#print img['src']

	#retrieving captcha image
	br.retrieve("https://vtop.vit.ac.in/student/"+img['src'], reg_no+".bmp")
	print "captcha retrieved"

	#opening the image
	img = Image.open(reg_no+".bmp")

	#parsing the image and getting its string value
	parser = CaptchaParser()
	captcha = parser.getCaptcha(img)
	print str(captcha)

	os.remove(reg_no+".bmp")

	#filling form
	br["regno"] = str(reg_no)
	br["passwd"] = str(pwd)
	br["vrfcd"] = str(captcha)

	#submitting the values and signing in
	br.method = "POST"
	response = br.submit()

	#during the time of rivera
	try:

		br.open("https://vtop.vit.ac.in/student/stud_home.asp")
		br.select_form("stud_riviera")
		br.submit(label = "Skip Now")
		print "Login_Sucess"

	#for normal login
	except:

		print "Login_Sucess"

	return br
Esempio n. 6
0
from CaptchaParser import CaptchaParser
import timeit
from PIL import Image
f = []
for (dirpath, dirnames, filenames) in walk('samples'):
    f.extend(filenames)
    break
timesum = 0
size = len(f)
count = 1
maxtime = 0
mintime = 100
currtime = 0
for im in f:
    img = Image.open("samples/" + str(im))
    c = CaptchaParser()
    starttime = timeit.default_timer()
    print "CAPTCHA:" + c.getCaptcha(img)
    endtime = timeit.default_timer()
    currtime = endtime - starttime
    if (currtime > maxtime):
        maxtime = currtime
        maximg = img.copy()
        print "new max:" + str(maxtime)
    if (currtime < mintime):
        mintime = currtime
        minimg = img.copy()
        print "new min:" + str(mintime)

    timesum += currtime
    print "Comparing image " + str(count) + "/" + str(size)
def get_atten(reg_no="", pwd="", mob_num=""):

    import mechanize, json, datetime, pytz
    from bs4 import BeautifulSoup
    from CaptchaParser import CaptchaParser
    from PIL import Image

    #browser initialise
    br = mechanize.Browser()
    br.set_handle_robots(False)
    br.set_handle_equiv(True)
    br.set_handle_gzip(True)
    br.set_handle_redirect(True)
    br.set_handle_referer(True)

    #open website

    # response = br.open("https://academics.vit.ac.in/student/stud_login.asp")
    response = br.open("https://vtop.vit.ac.in/parent/parent_login.asp")
    print br.geturl()

    #select form
    br.select_form("parent_login")

    #extracting captcha url
    soup = BeautifulSoup(response.get_data())
    img = soup.find('img', id='imgCaptcha')

    #retrieving captcha image
    br.retrieve("https://vtop.vit.ac.in/parent/" + img['src'],
                "captcha_parent.bmp")

    # print str("https://academics.vit.ac.in/parent/"+img['src'], "captcha_parent")

    img = Image.open("captcha_parent.bmp")

    parser = CaptchaParser()

    captcha = parser.getCaptcha(img)

    #fill form
    br["wdregno"] = str(reg_no)
    br["wdpswd"] = str(pwd)
    br["wdmobno"] = str(mob_num)
    br["vrfcd"] = str(captcha)
    br.method = "POST"
    br.submit()
    if br.geturl() == ("https://vtop.vit.ac.in/parent/home.asp"):
        print "SUCCESS"

        #attendance page
        months = {
            1: "Jan",
            2: "Feb",
            3: "Mar",
            4: "Apr",
            5: "May",
            6: "Jun",
            7: "Jul",
            8: "Aug",
            9: "Sep",
            10: "Oct",
            11: "Nov",
            12: "Dec"
        }
        atten = {}
        br.open("https://vtop.vit.ac.in/parent/attn_report.asp?sem=WS")
        response = br.open(
            "https://vtop.vit.ac.in/parent/attn_report.asp?sem=WS")
        soup = BeautifulSoup(response.get_data())

        br.select_form(nr=0)
        inputTag = soup.find(attrs={"name": "from_date"})
        from_date = inputTag['value']
        tz = pytz.timezone('Asia/Kolkata')
        now = datetime.datetime.now(tz)
        to_date = str(now.day) + "-" + months[now.month] + "-" + str(now.year)

        response = br.open(
            "https://vtop.vit.ac.in/parent/attn_report.asp?sem=WS&fmdt=%(from_date)s&todt=%(to_date)s"
            % {
                "from_date": from_date,
                "to_date": to_date
            })
        soup = BeautifulSoup(response.get_data())
        tables = soup.findAll("table")
        trs = soup.findAll("table")[len(tables) - 2].findAll("tr")
        for i in range(
                1, len(trs)):  #it should be len(trs) -1 but it works w/o -1
            a_course_code = soup.findAll("table")[len(tables) - 2].findAll(
                "tr")[i].findAll("td")[1].getText().encode('utf-8').replace(
                    "\xc2\xa0", " ")
            a_attend_percentage = soup.findAll("table")[
                len(tables) - 2].findAll("tr")[i].findAll(
                    "td")[8].getText().encode('utf-8').replace(
                        "\xc2\xa0", " ")
            if a_course_code not in atten.keys():
                atten[a_course_code] = [a_attend_percentage]
            else:
                atten[a_course_code + "_L"] = [a_attend_percentage]

        return {"Status": "sucess", "attendance": atten}