Skip to content

Instantly share code, notes, and snippets.

Created August 11, 2016 03:46
Show Gist options
  • Select an option

  • Save anonymous/70f1da35722fbff1ff7f0383c505a546 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/70f1da35722fbff1ff7f0383c505a546 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
import urllib
from datetime import datetime
now = datetime.now()
hour = str(now.hour)
min = str(now.minute)
sec = str(now.second)
s = requests.Session()
url = 'https://nucleus.niituniversity.in/'
getUrl = s.get(url)
con = getUrl.content
parser = "html5lib"
soup = BeautifulSoup(con,parser)
cookie = getUrl.cookies['ASP.NET_SessionId']
print(str(cookie))
session_cookies = {'ASP.NET_Session_Id' : cookie}
login_dataUrl = "https://nucleus.niituniversity.in/GetLoginData.aspx"
url2 = "https://nucleus.niituniversity.in/&TIME=Thu Aug 11 2016 " + hour + ":" + min + ":" + sec + " GMT+0530 (India Standard Time)"
#What you have pointed out is here
payload = {
'username' : 'U101114FCS059',
'categoryid' : '3',
'URL' : url2
}
r = s.get(login_dataUrl,params = payload)
x = urllib.parse.unquote_plus(r.url,encoding = 'utf-8')
s.get(x,cookies = session_cookies)
'''
login_data = {'ScriptManager1' : 'SchSel$up|SchSel$btnLogin',
'__LASTFOCUS' : '',
'__EVENTTARGET' : '',
'__EVENTARGUMENT' : '',
'__VIEWSTATE' : soup.select_one("#__VIEWSTATE")["value"],
'__VIEWSTATEGENERATOR' : soup.select_one("#__VIEWSTATEGENERATOR")["value"],
'SchSel$cmbUserType' : 'Student',
'SchSel$txtUserName' : 'Username',
'SchSel$txtPassword' : 'Password',
'SchSel$chkSkip' : 'on',
'SchSel$hidLastLogin' : 'Last Login: NIIT University | 2016-2017',
'SchSel$hidSchoolId' : '1',
'SchSel$hidSchoolName' : 'NIIT University',
'SchSel$hidCoreUserDet' : '815207',
'SchSel$hidSessionId' : '3',
'SchSel$hidActiveSchool' : '1',
'SchSel$hidReportingDet' : '0',
'SchSel$hidActiveSession' : '1',
'SchSel$hidHitCount' : '3',
'SchSel$hidSchoolAddress' : 'NH-8, Delhi-Jaipur HighwayNeemrana - 301705',
'SchSel$hdnLoginAsUser' : '',
'__ASYNCPOST' : 'true',
'SchSel$btnLogin.x' : '42',
'SchSel$btnLogin.y' : '14'
}
'''
headers = {
'Referer' : 'https://nucleus.niituniversity.in'
}
s.headers.update(headers)
print(str(soup.select_one("#SchSel_hidCoreUserDet")["value"]))
try:
r = s.post(url, data=login_data, cookies = session_cookies)
res = s.get('https://nucleus.niituniversity.in/WebApp/Index.aspx').content #Protected page
except Exception as e:
print(str(e))
f = open("check.txt","w+",encoding = 'utf-8')
f.write(str(BeautifulSoup(res,parser)))
f.flush()
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment